Advertisement
rfmonk

smtplib_sendmail.py

Feb 21st, 2014
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. import smtplib
  5. import email.utils
  6. from email.mime.text import MIMEText
  7.  
  8. # Create the message
  9. msg = MIMEText('This is the body of the message.')
  10. msg['To'] = email.utils.formataddr(('Recipient',
  11.                                     'recipient@example.com'))
  12. msg['From'] = email.utils.formataddr(('Author',
  13.                                       'author@example.com'))
  14. msg['Subject'] = 'Simple test message'
  15.  
  16. server = smtplib.SMTP('mail')
  17. server.set_debuglevel(True)  # show communication with the server
  18. try:
  19.     server.sendmail('author@example.com',
  20.                     ['recipient@example.com'],
  21.                     msg.as_string())
  22. finally:
  23.     server.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement