1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
5 Demonstrate sending mail via SMTP.
9 from email.mime.text import MIMEText
11 from twisted.python import log
12 from twisted.mail.smtp import sendmail
13 from twisted.internet import reactor
16 def send(message, subject, sender, recipients, host):
18 Send email to one or more addresses.
20 msg = MIMEText(message)
21 msg['Subject'] = subject
23 msg['To'] = ', '.join(recipients)
25 dfr = sendmail(host, sender, recipients, msg.as_string())
31 dfr.addCallback(success)
37 if __name__ == '__main__':
38 msg = 'This is the message body'
39 subject = 'This is the message subject'
41 host = 'smtp.example.com'
42 sender = 'sender@example.com'
43 recipients = ['recipient@example.com']
45 log.startLogging(sys.stdout)
46 send(msg, subject, sender, recipients, host)