Modify

Opened 7 years ago

Closed 21 months ago

#1281 closed enhancement (wontfix)

Enabling SMTP TLS

Reported by: sstults Owned by: athomas
Priority: normal Component: WikiNotifyScript
Severity: normal Keywords:
Cc: sstults@… Trac Release: 0.10

Description

I needed to enable TLS for communicating with our SMTP server. Basically I lifted the TLS code from trac notification.py. There also seemed to be a duplicate smtp setup line, which I deleted. Below is an svn diff:

Index: trac-wiki-notify
===================================================================
--- trac-wiki-notify    (revision 2078)
+++ trac-wiki-notify    (working copy)
@@ -35,6 +35,8 @@
 import re
 from time import strftime, localtime, time

+_use_tls = True
+
 if len(sys.argv) < 5:
     raise StandardError("Not enough arguments")

@@ -75,7 +77,14 @@
         email_body += "\nYou can remove yourself from notifications at this URL:\n  %swiki/%s\n" % (trac_url, notify_page)

         smtp = smtplib.SMTP(smtp_server)
-        smtp = smtplib.SMTP(smtp_server)
+
+        if _use_tls:
+            smtp.ehlo()
+            if not smtp.esmtp_features.has_key('starttls'):
+                raise StandardError, "TLS enabled but server does not support TLS"
+            smtp.starttls()
+            smtp.ehlo()
+
         # Finish the email
         for email in smtp_to:
             smtp_body = "From: %s\n" % smtp_from
@@ -86,7 +95,16 @@
             # Send the mail
             smtp.sendmail(smtp_from, email, smtp_body)

-        smtp.quit()
+        if _use_tls:
+            # avoid false failure detection when the server closes
+            # the SMTP connection with TLS enabled
+            import socket
+            try:
+                smtp.quit()
+            except socket.sslerror:
+                pass
+        else:
+            smtp.quit()

         # Write logfile (or not)
         if len(sys.argv) > 7:

Attachments (0)

Change History (2)

comment:1 Changed 7 years ago by rackingguy

Looks like what we're looking for. I support this change.

comment:2 Changed 21 months ago by rjollos

  • Resolution set to wontfix
  • Status changed from new to closed

This script is deprecated. Please take a look at the AnnouncerPlugin and WatchlistPlugin.

Add Comment

Modify Ticket

Action
as closed .
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from athomas. Next status will be 'closed'.
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.