16 de mar. de 2011

como enviar email smtp ( python )

#!/usr/bin/python

import smtplib

sender = 'remetente@dominio.com'
receivers = ['destinatario@dominio.com']

message = """From: From Person <from@fromdomain.com>
To: To Person <to@todomain.com>
Subject: SMTP e-mail test

This is a test e-mail message.
"""

try:
   smtpObj = smtplib.SMTP('localhost')
   smtpObj.sendmail(sender, receivers, message)        
   print "Successfully sent email"
except SMTPException:
   print "Error: unable to send email"

Nenhum comentário:

Postar um comentário