Revision: 3643 http://trac.macosforge.org/projects/calendarserver/changeset/3643 Author: sagen@apple.com Date: 2009-02-05 13:40:38 -0800 (Thu, 05 Feb 2009) Log Message: ----------- Support password auth and SSL for outbound iMIP messages over SMTP Modified Paths: -------------- CalendarServer/trunk/conf/caldavd-test.plist CalendarServer/trunk/conf/caldavd.plist CalendarServer/trunk/twistedcaldav/config.py CalendarServer/trunk/twistedcaldav/mail.py Modified: CalendarServer/trunk/conf/caldavd-test.plist =================================================================== --- CalendarServer/trunk/conf/caldavd-test.plist 2009-02-05 20:36:21 UTC (rev 3642) +++ CalendarServer/trunk/conf/caldavd-test.plist 2009-02-05 21:40:38 UTC (rev 3643) @@ -526,6 +526,12 @@ <string></string> <key>Port</key> <integer>587</integer> + <key>UseSSL</key> + <true/> + <key>Username</key> + <string></string> + <key>Password</key> + <string></string> <key>Address</key> <string></string> <!-- Address email will be sent from --> </dict> Modified: CalendarServer/trunk/conf/caldavd.plist =================================================================== --- CalendarServer/trunk/conf/caldavd.plist 2009-02-05 20:36:21 UTC (rev 3642) +++ CalendarServer/trunk/conf/caldavd.plist 2009-02-05 21:40:38 UTC (rev 3643) @@ -400,6 +400,12 @@ <string></string> <key>Port</key> <integer>587</integer> + <key>UseSSL</key> + <true/> + <key>Username</key> + <string></string> + <key>Password</key> + <string></string> <key>Address</key> <string></string> <!-- Address email will be sent from --> </dict> Modified: CalendarServer/trunk/twistedcaldav/config.py =================================================================== --- CalendarServer/trunk/twistedcaldav/config.py 2009-02-05 20:36:21 UTC (rev 3642) +++ CalendarServer/trunk/twistedcaldav/config.py 2009-02-05 21:40:38 UTC (rev 3643) @@ -261,6 +261,9 @@ "Server" : "", # SMTP server to relay messages through "Port" : 587, # SMTP server port to relay messages through "Address" : "", # 'From' address for server + "UseSSL" : True, + "Username" : "", # For account sending mail + "Password" : "", # For account sending mail }, "Receiving": { "Server" : "", # Server to retrieve email messages from Modified: CalendarServer/trunk/twistedcaldav/mail.py =================================================================== --- CalendarServer/trunk/twistedcaldav/mail.py 2009-02-05 20:36:21 UTC (rev 3642) +++ CalendarServer/trunk/twistedcaldav/mail.py 2009-02-05 21:40:38 UTC (rev 3643) @@ -25,10 +25,10 @@ from email.mime.text import MIMEText from twisted.application import internet, service -from twisted.internet import protocol, defer, ssl +from twisted.internet import protocol, defer, ssl, reactor from twisted.internet.defer import inlineCallbacks, returnValue, succeed from twisted.mail import pop3client, imap4 -from twisted.mail.smtp import messageid, rfc822date, sendmail +from twisted.mail.smtp import messageid, rfc822date, ESMTPSenderFactory from twisted.plugin import IPlugin from twisted.python.usage import Options, UsageError from twisted.web import resource, server, client @@ -56,6 +56,13 @@ import os import uuid +try: + from cStringIO import StringIO +except ImportError: + from StringIO import StringIO + + + __all__ = [ "IMIPInboxResource", "MailGatewayServiceMaker", @@ -793,9 +800,20 @@ self.log_error("Mail gateway failed to send message %s from %s to %s (Reason: %s)" % (msgId, fromAddr, toAddr, failure.getErrorMessage())) - deferred = sendmail(settings['Server'], fromAddr, toAddr, message, - port=settings['Port']) + deferred = defer.Deferred() + if settings["UseSSL"]: + contextFactory = ssl.ClientContextFactory() + else: + contextFactory = None + + factory = ESMTPSenderFactory(settings['Username'], settings['Password'], + fromAddr, toAddr, StringIO(str(message)), deferred, + contextFactory=contextFactory, + requireAuthentication=False, + requireTransportSecurity=False) + + reactor.connectTCP(settings['Server'], settings['Port'], factory) deferred.addCallback(_success, msgId, fromAddr, toAddr) deferred.addErrback(_failure, msgId, fromAddr, toAddr)
participants (1)
-
source_changes@macosforge.org