Edgewall Software

Changes between Version 1 and Version 2 of Ticket #12419, comment 4


Ignore:
Timestamp:
Mar 26, 2016, 12:03:45 AM (8 years ago)
Author:
Christian Boos

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #12419, comment 4

    v1 v2  
    77
    88Ok, what about:
    9 (scratch that...)
     9{{{#!diff
     10diff --git a/trac/notification/mail.py b/trac/notification/mail.py
     11index 2bccf87..9606052 100644
     12--- a/trac/notification/mail.py
     13+++ b/trac/notification/mail.py
     14@@ -61,6 +61,7 @@ EMAIL_LOOKALIKE_PATTERN = (
     15
     16 _mime_encoding_re = re.compile(r'=\?[^?]+\?[bq]\?[^?]+\?=', re.IGNORECASE)
     17
     18+local_hostname = None
     19
     20
     21 def create_charset(mime_encoding):
     22@@ -433,13 +434,16 @@ class SmtpEmailSender(Component):
     23         """Use SSL/TLS to send notifications over SMTP.""")
     24
     25     def send(self, from_addr, recipients, message):
     26+        global local_hostname
     27         # Ensure the message complies with RFC2822: use CRLF line endings
     28         message = fix_eol(message, CRLF)
     29
     30         self.log.info("Sending notification through SMTP at %s:%d to %s",
     31                       self.smtp_server, self.smtp_port, recipients)
     32         try:
     33-            server = smtplib.SMTP(self.smtp_server, self.smtp_port, 'localhost')
     34+            server = smtplib.SMTP(self.smtp_server, self.smtp_port,
     35+                                  local_hostname)
     36+            local_hostname = server.local_hostname
     37         except smtplib.socket.error as e:
     38             raise ConfigurationError(
     39                 tag_("SMTP server connection error (%(error)s). Please "
     40}}}
     41(caching it on the component doesn't help much for the tests, since the reuse rate is very low)
    1042
    1143`smtplib.SMTP.local_hostname` isn't part of the "public" API, however it looks stable enough to me (present from at least from Python 2.4.4 to current head).