Sendmail with many attach and recipients
Tim Williams
listserver at tdw.net
Thu Feb 3 12:22:35 EST 2005
<fernandestb at gmail.com> wrote in message
news:81b88e49.0502030850.490952c9 at posting.google.com...
Here, my code of sendmail
If Somebody had a doubt please contact me?
fernandestb at gmail.com
[snip]
If you have multiple recipients, you need to modify
server.sendmail(msg['From'],toaddrs,msg.as_string())
to
failed = server.sendmail(msg['From'],toaddrs,msg.as_string())
# exception is only raised if ALL recips fail
# failed is a list of failed recips, or empty
You could also expand your smtplib exception handling
[not tested]
try:
server = smtplib.SMTP(servidor_smtp)
## Faz o envio do email.
try:
failed = server.sendmail(msg['From'],toaddrs,msg.as_string())
if failed:
do something
## Fecha a conexão com o servidor
except smtplib.SMTPRecipientsRefused, x : #all recips failed before
data sent = MSG failed
do something
except smtplip.SMTPDataError, x: # an error at the end of the
message body receipt = MSG Failed
do something
except smtplib.SMTPSenderRefused, x : # the sender was refused = MSG
failed
do something
except: #can't connect
do something
finally
server.quit()
except Exception, e:
arq=open(dir_log,'a')
print >> arq, "Falha no envio da mensagem de email, não foi
--
=================================
Tim Williams
More information about the Python-list
mailing list