Sendmail with many attach and recipients

T

Tim Williams

Here, my code of sendmail
If Somebody had a doubt please contact me?
(e-mail address removed)

[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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top