@@ -53,41 +53,44 @@ def send_smtp(msg, bcc=None):
5353 if bcc :
5454 addrlist += [bcc ]
5555 to = [addr for name , addr in getaddresses (addrlist )]
56- if test_mode :
57- outbox .append ((msg , to , msg .as_string ()))
58- return
59- server = None
60- try :
61- server = smtplib .SMTP ()
62- if settings .DEBUG :
63- server .set_debuglevel (1 )
64- server .connect (settings .EMAIL_HOST , settings .EMAIL_PORT )
65- if settings .EMAIL_HOST_USER and settings .EMAIL_HOST_PASSWORD :
66- server .ehlo ()
67- if 'starttls' not in server .esmtp_features :
68- raise ImproperlyConfigured ('password configured but starttls not supported' )
69- (retval , retmsg ) = server .starttls ()
70- if retval != 220 :
71- raise ImproperlyConfigured ('password configured but tls failed: %d %s' % ( retval , retmsg ))
72- # Send a new EHLO, since without TLS the server might not
73- # advertise the AUTH capability.
74- server .ehlo ()
75- server .login (settings .EMAIL_HOST_USER , settings .EMAIL_HOST_PASSWORD )
76- server .sendmail (frm , to , msg .as_string ())
77- # note: should pay attention to the return code, as it may
78- # indicate that someone didn't get the email.
79- except :
80- if server :
81- server .quit ()
82- # need to improve log message
83- log ("got exception '%s' (%s) trying to send email from '%s' to %s subject '%s'" % (sys .exc_info ()[0 ], sys .exc_info ()[1 ], frm , to , msg .get ('Subject' , '[no subject]' )))
84- if isinstance (sys .exc_info ()[0 ], smtplib .SMTPException ):
85- raise
86- else :
87- raise smtplib .SMTPException ({'really' : sys .exc_info ()[0 ], 'value' : sys .exc_info ()[1 ], 'tb' : sys .exc_info ()[2 ]})
88- server .quit ()
89- log ("sent email from '%s' to %s subject '%s'" % (frm , to , msg .get ('Subject' , '[no subject]' )))
90-
56+ if not to :
57+ log ("No addressees for email from '%s', subject '%s'. Nothing sent." % (frm , msg .get ('Subject' , '[no subject]' )))
58+ else :
59+ if test_mode :
60+ outbox .append ((msg , to , msg .as_string ()))
61+ return
62+ server = None
63+ try :
64+ server = smtplib .SMTP ()
65+ if settings .DEBUG :
66+ server .set_debuglevel (1 )
67+ server .connect (settings .EMAIL_HOST , settings .EMAIL_PORT )
68+ if settings .EMAIL_HOST_USER and settings .EMAIL_HOST_PASSWORD :
69+ server .ehlo ()
70+ if 'starttls' not in server .esmtp_features :
71+ raise ImproperlyConfigured ('password configured but starttls not supported' )
72+ (retval , retmsg ) = server .starttls ()
73+ if retval != 220 :
74+ raise ImproperlyConfigured ('password configured but tls failed: %d %s' % ( retval , retmsg ))
75+ # Send a new EHLO, since without TLS the server might not
76+ # advertise the AUTH capability.
77+ server .ehlo ()
78+ server .login (settings .EMAIL_HOST_USER , settings .EMAIL_HOST_PASSWORD )
79+ server .sendmail (frm , to , msg .as_string ())
80+ # note: should pay attention to the return code, as it may
81+ # indicate that someone didn't get the email.
82+ except :
83+ if server :
84+ server .quit ()
85+ # need to improve log message
86+ log ("got exception '%s' (%s) trying to send email from '%s' to %s subject '%s'" % (sys .exc_info ()[0 ], sys .exc_info ()[1 ], frm , to , msg .get ('Subject' , '[no subject]' )))
87+ if isinstance (sys .exc_info ()[0 ], smtplib .SMTPException ):
88+ raise
89+ else :
90+ raise smtplib .SMTPException ({'really' : sys .exc_info ()[0 ], 'value' : sys .exc_info ()[1 ], 'tb' : sys .exc_info ()[2 ]})
91+ server .quit ()
92+ log ("sent email from '%s' to %s subject '%s'" % (frm , to , msg .get ('Subject' , '[no subject]' )))
93+
9194def copy_email (msg , to , toUser = False ):
9295 '''
9396 Send a copy of the given email message to the given recipient.
0 commit comments