Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2016
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. #! /usr/local/bin/python
  2.  
  3.  
  4. SMTPserver = 'smtp.att.yahoo.com'
  5. sender =     'me@my_email_domain.net'
  6. destination = ['recipient@her_email_domain.com']
  7.  
  8. USERNAME = "USER_NAME_FOR_INTERNET_SERVICE_PROVIDER"
  9. PASSWORD = "PASSWORD_INTERNET_SERVICE_PROVIDER"
  10.  
  11. # typical values for text_subtype are plain, html, xml
  12. text_subtype = 'plain'
  13.  
  14.  
  15. content="""\
  16. Test message
  17. """
  18.  
  19. subject="Sent from Python"
  20.  
  21. import sys
  22. import os
  23. import re
  24.  
  25. from smtplib import SMTP_SSL as SMTP       # this invokes the secure SMTP protocol (port 465, uses SSL)
  26. # from smtplib import SMTP                  # use this for standard SMTP protocol   (port 25, no encryption)
  27.  
  28. # old version
  29. # from email.MIMEText import MIMEText
  30. from email.mime.text import MIMEText
  31.  
  32. try:
  33.     msg = MIMEText(content, text_subtype)
  34.     msg['Subject']=       subject
  35.     msg['From']   = sender # some SMTP servers will do this automatically, not all
  36.  
  37.     conn = SMTP(SMTPserver)
  38.     conn.set_debuglevel(False)
  39.     conn.login(USERNAME, PASSWORD)
  40.     try:
  41.         conn.sendmail(sender, destination, msg.as_string())
  42.     finally:
  43.         conn.quit()
  44.  
  45. except Exception, exc:
  46.     sys.exit( "mail failed; %s" % str(exc) ) # give a error message
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement