[Python-checkins] hooks: allow smtp username and password

benjamin.peterson python-checkins at python.org
Fri Sep 12 22:32:28 CEST 2014


http://hg.python.org/hooks/rev/181e6ea1e92a
changeset:   92:181e6ea1e92a
user:        Benjamin Peterson <benjamin at python.org>
date:        Fri Sep 12 20:30:47 2014 +0000
summary:
  allow smtp username and password

files:
  hgroundup.py |  14 ++++++++------
  1 files changed, 8 insertions(+), 6 deletions(-)


diff --git a/hgroundup.py b/hgroundup.py
--- a/hgroundup.py
+++ b/hgroundup.py
@@ -22,7 +22,6 @@
     [hgroundup]
     fromaddr = roundup-user at example.com
     toaddr = roundup-admin at example.com
-    mailrelay = 127.0.0.1
 
 `fromaddr` must be registered as the address of an existing Roundup user,
 otherwise Roundup will refuse and bounce the message.
@@ -69,9 +68,6 @@
         repourl = posixpath.join(ui.config('web', 'baseurl'), 'rev/')
     fromaddr = ui.config('hgroundup', 'fromaddr')
     toaddr = ui.config('hgroundup', 'toaddr')
-    mailrelay = ui.config('hgroundup', 'mailrelay', default='')
-    if not mailrelay:
-        mailrelay = ui.config('smtp', 'host', default='')
     for var in ('repourl', 'fromaddr', 'toaddr'):
         if not locals()[var]:
             raise RuntimeError(
@@ -103,6 +99,13 @@
             })
             add_comment(issues, data, comment)
     if issues:
+        smtp_host = ui.config('smtp', 'host', default='localhost')
+        smtp_port = int(ui.config('smtp', 'port', 25))
+        s = smtplib.SMTP(smtp_host, smtp_port)
+        username = ui.config('smtp', 'username', '')
+        if username:
+          password = ui.config('smtp', 'password', '')
+          s.login(username, password)
         try:
             send_comments(mailrelay, fromaddr, toaddr, issues)
             ui.status("sent email to roundup at " + toaddr + '\n')
@@ -129,9 +132,8 @@
             'stage': 'resolved',
         })
 
-def send_comments(mailrelay, fromaddr, toaddr, issues):
+def send_comments(s, fromaddr, toaddr, issues):
     """Update the Roundup issue with a comment and changeset link."""
-    s = smtplib.SMTP(mailrelay)
     try:
         for issue_id, data in issues.iteritems():
             props = ''

-- 
Repository URL: http://hg.python.org/hooks


More information about the Python-checkins mailing list