Better error handling when sending an email.

This commit is contained in:
Antoine Nguyen
2013-06-14 15:04:10 +02:00
parent 1e78648ecd
commit 679f0439b7
2 changed files with 9 additions and 2 deletions
+6 -2
View File
@@ -695,8 +695,12 @@ def send_mail(request, posturl=None):
s.login(request.user.username, get_password(request))
except smtplib.SMTPException, e:
raise WebmailError(str(e))
s.sendmail(request.user.email, rcpts, msg.as_string())
s.quit()
try:
s.sendmail(request.user.email, rcpts, msg.as_string())
s.quit()
except smtplib.SMTPException, e:
raise WebmailError(str(e))
sentfolder = parameters.get_user(request.user, "SENT_FOLDER")
IMAPconnector(user=request.user.username,
password=request.session["password"]).push_mail(sentfolder, msg)
+3
View File
@@ -218,6 +218,9 @@ def decode(s, encodings=('utf8', 'latin1', 'windows-1252', 'ascii'), charset=Non
def prepare_addresses(addresses, usage="header"):
"""Prepare addresses before using them
FIXME: We need a real address parser here! If a name contains a
separator, it creates two wrong addresses.
:param list addresses: a list of addresses
:param string usage: how those addresses are going to be used
:return: a string or a list depending on usage value