Hi all,

just in case anyone runs into the same problem, a short update with a
solution.

On 08/12/2011 01:59 PM, Enis Afgan wrote:

> On Fri, Aug 12, 2011 at 4:37 AM, Holger Klein <h.kl...@imb-mainz.de
> <mailto:h.kl...@imb-mainz.de>> wrote:
> 
>     Hi Dannon,
> 
>     thanks for the info. I'd like to take this a small step further. I added
>     the variable smtp_from to universe_wsgi.ini. Then I modified the
>     util.send_mail in ./lib/galaxy/util/__init__.py to check if
>     config.smtp_from is set:
> 
>        if config.smtp_from is None:
>            msg[ 'From' ] = frm
>        else:
>            msg[ 'From' ] = config.smtp_from
> 
>     Still frm is set to the old value (galaxy-no-reply@computeserver). Can
>     anyone point me to the place where universe_wsgi.ini is actually parsed
>     and the config dictionary is filled?
> 
> 
> The parsing of the config file is done as part of Python's paste and
> it's then made available to the rest of Galaxy via lib/galaxy/config.py.
> There is only one instance of that class for the entire app but the
> send_mail method you were looking at does not have access to that
> object. So, you should look higher up in the hierarchy and set frm in
> the method that calls send_mail (there seem to be several places where
> it's called).

The send_mail method gets "config" as the last argument, so the
variables from universe_wsgi.ini are accessible within the function.
I did the following:
1) modify universe_wsgi.ini:
   add the line
   smtp_from = desired_f...@localhost.net
2) modify galaxy-dist/lib/galaxy/config.py:
   add the line
   self.smtp_from = kwargs.get( 'smtp_from', None )
3) modify function send_mail in galaxy-dist/lib/galaxy/util/__init__.py:
   line 550:

   ## msg[ 'From' ] = frm
   if config.smtp_from is None:
        msg[ 'From' ] = frm
        smtp_frm = frm
    else:
        msg[ 'From' ] = config.smtp_from
        smtp_frm = config.smtp_from

   [...]
   ## end of function send_mail:
   ## s.sendmail( frm, to, msg.as_string() )
   s.sendmail( smtp_frm, to, msg.as_string() )

Now galaxy checks if the variable smtp_from is set; if yes, it adjusts
the from header in all cases the send_mail function is used, otherwise
it uses the old method.

I attach patches, feel free to add if you think this could be useful for
anyone else but me.

Cheers,
Holger





-- 
Dr. Holger Klein
Core Facility Bioinformatics
Institute of Molecular Biology gGmbH (IMB)
http://www.imb-mainz.de/
Tel: +49(6131) 39 21511
diff -r 720455407d1c lib/galaxy/config.py
--- a/lib/galaxy/config.py      Thu Jun 23 11:03:45 2011 -0400
+++ b/lib/galaxy/config.py      Mon Aug 15 14:48:32 2011 +0200
@@ -74,16 +74,17 @@ class Configuration( object ):
         self.output_size_limit = int( kwargs.get( 'output_size_limit', 0 ) )
         self.job_walltime = kwargs.get( 'job_walltime', None )
         self.admin_users = kwargs.get( "admin_users", "" )
         self.mailing_join_addr = 
kwargs.get('mailing_join_addr',"galaxy-user-j...@bx.psu.edu")
         self.error_email_to = kwargs.get( 'error_email_to', None )
         self.smtp_server = kwargs.get( 'smtp_server', None )
         self.smtp_username = kwargs.get( 'smtp_username', None )
         self.smtp_password = kwargs.get( 'smtp_password', None )
+        self.smtp_from = kwargs.get( 'smtp_from', None )
         self.start_job_runners = kwargs.get( 'start_job_runners', None )
         # External Service types used in sample tracking
         self.external_service_type_config_file = resolve_path( kwargs.get( 
'external_service_type_config_file', 'external_service_types_conf.xml' ), 
self.root )
         self.external_service_type_path = resolve_path( kwargs.get( 
'external_service_type_path', 'external_service_types' ), self.root )
         # Tasked job runner.
         self.use_tasked_jobs = string_as_bool( kwargs.get( 'use_tasked_jobs', 
False ) )
         # The transfer manager and deferred job queue
         self.enable_beta_job_managers = string_as_bool( kwargs.get( 
'enable_beta_job_managers', 'False' ) )
diff -r 720455407d1c lib/galaxy/util/__init__.py
--- a/lib/galaxy/util/__init__.py       Thu Jun 23 11:03:45 2011 -0400
+++ b/lib/galaxy/util/__init__.py       Mon Aug 15 14:44:33 2011 +0200
@@ -542,17 +542,26 @@ def nice_size(size):
     return '??? bytes'
 
 def send_mail( frm, to, subject, body, config ):
     """
     Sends an email.
     """
     msg = MIMEText( body )
     msg[ 'To' ] = to
-    msg[ 'From' ] = frm
+    
+    log.warning( '1config-from: %s' % config.smtp_from )
+    log.warning( '1FROM: %s' % frm )
+    log.warning( 'body: %s' % body )
+    if config.smtp_from is None:
+        msg[ 'From' ] = frm
+        smtp_frm = frm
+    else:
+        msg[ 'From' ] = config.smtp_from
+        smtp_frm = config.smtp_from
     msg[ 'Subject' ] = subject
     if config.smtp_server is None:
         log.error( "Mail is not configured for this Galaxy instance." )
         log.info( msg )
         return
     s = smtplib.SMTP()
     s.connect( config.smtp_server )
     try:
@@ -578,17 +587,17 @@ def send_mail( frm, to, subject, body, c
             s.close()
             raise
         except smtplib.SMTPError, e:
             log.error( "No suitable authentication method was found: %s" % e )
             s.close()
             raise
     if isinstance( to, basestring ):
         to = [ to ]
-    s.sendmail( frm, to, msg.as_string() )
+    s.sendmail( smtp_frm, to, msg.as_string() )
     s.quit()
 
 galaxy_root_path = os.path.join(__path__[0], "..","..","..")
 # The dbnames list is used in edit attributes and the upload tool
 dbnames = read_dbnames( os.path.join( galaxy_root_path, "tool-data", "shared", 
"ucsc", "builds.txt" ) )
 ucsc_build_sites = read_build_sites( os.path.join( galaxy_root_path, 
"tool-data", "shared", "ucsc", "ucsc_build_sites.txt" ) )
 gbrowse_build_sites = read_build_sites( os.path.join( galaxy_root_path, 
"tool-data", "shared", "gbrowse", "gbrowse_build_sites.txt" ) )
 genetrack_sites = read_build_sites( os.path.join( galaxy_root_path, 
"tool-data", "shared", "genetrack", "genetrack_sites.txt" ), check_builds=False 
)
___________________________________________________________
Please keep all replies on the list by using "reply all"
in your mail client.  To manage your subscriptions to this
and other Galaxy lists, please use the interface at:

  http://lists.bx.psu.edu/

Reply via email to