SHARE
TWEET

Untitled

a guest Jun 29th, 2018 368 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from smtplib import SMTP
  2. import datetime
  3.  
  4. debuglevel = 0
  5.  
  6. smtp = SMTP()
  7. smtp.set_debuglevel(debuglevel)
  8. smtp.connect('YOUR.MAIL.SERVER', 26)
  9. smtp.login('USERNAME@DOMAIN', 'PASSWORD')
  10.  
  11. from_addr = "John Doe <john@doe.net>"
  12. to_addr = "foo@bar.com"
  13.  
  14. subj = "hello"
  15. date = datetime.datetime.now().strftime( "%d/%m/%Y %H:%M" )
  16.  
  17. message_text = "HellonThis is a mail from your servernnByen"
  18.  
  19. msg = "From: %snTo: %snSubject: %snDate: %snn%s"
  20.         % ( from_addr, to_addr, subj, date, message_text )
  21.  
  22. smtp.sendmail(from_addr, to_addr, msg)
  23. smtp.quit()
  24.    
  25. #! /usr/local/bin/python
  26.  
  27.  
  28. SMTPserver = 'smtp.att.yahoo.com'
  29. sender =     'me@my_email_domain.net'
  30. destination = ['recipient@her_email_domain.com']
  31.  
  32. USERNAME = "USER_NAME_FOR_INTERNET_SERVICE_PROVIDER"
  33. PASSWORD = "PASSWORD_INTERNET_SERVICE_PROVIDER"
  34.  
  35. # typical values for text_subtype are plain, html, xml
  36. text_subtype = 'plain'
  37.  
  38.  
  39. content="""
  40. Test message
  41. """
  42.  
  43. subject="Sent from Python"
  44.  
  45. import sys
  46. import os
  47. import re
  48.  
  49. from smtplib import SMTP_SSL as SMTP       # this invokes the secure SMTP protocol (port 465, uses SSL)
  50. # from smtplib import SMTP                  # use this for standard SMTP protocol   (port 25, no encryption)
  51. from email.MIMEText import MIMEText
  52.  
  53. try:
  54.     msg = MIMEText(content, text_subtype)
  55.     msg['Subject']=       subject
  56.     msg['From']   = sender # some SMTP servers will do this automatically, not all
  57.  
  58.     conn = SMTP(SMTPserver)
  59.     conn.set_debuglevel(False)
  60.     conn.login(USERNAME, PASSWORD)
  61.     try:
  62.         conn.sendmail(sender, destination, msg.as_string())
  63.     finally:
  64.         conn.close()
  65.  
  66. except Exception, exc:
  67.     sys.exit( "mail failed; %s" % str(exc) ) # give a error message
  68.    
  69. ...
  70. smtp.connect('YOUR.MAIL.SERVER', 587)
  71. smtp.ehlo()
  72. smtp.starttls()
  73. smtp.ehlo()
  74. smtp.login('USERNAME@DOMAIN', 'PASSWORD')
  75. ...
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top