Advertisement
Guest User

Untitled

a guest
Sep 14th, 2018
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #! /usr/local/bin/python
  2.  
  3.  
  4. SMTPserver = 'email-smtp.us-west-2.amazonaws.com'
  5. sender = 'smastrian@ashion.com'
  6. destination = ['smastrian@ashion.com']
  7.  
  8. USERNAME = "AKIAJLHGQS6ZEH4DH3OA"
  9. PASSWORD = "Ahh497hW/gxLbw/ml4UWMdwYUn5sywwlPuQgu+XdVP0A"
  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:
  46. sys.exit( "mail failed; %s" % "CUSTOM_ERROR" ) # give an error message
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement