Modify

Opened 18 years ago

Closed 12 years ago

#1281 closed enhancement (wontfix)

Enabling SMTP TLS

Reported by: sstults Owned by: Alec Thomas
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 18 years ago by rackingguy

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

comment:2 Changed 12 years ago by Ryan J Ollos

Resolution: wontfix
Status: newclosed

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

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Alec Thomas.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


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

 
Note: See TracTickets for help on using tickets.