Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2011
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.48 KB | None | 0 0
  1. #! /usr/local/bin/python
  2. import sys
  3. from email.MIMEMultipart import MIMEMultipart
  4. from email.MIMEText import MIMEText
  5. from email.MIMEImage import MIMEImage
  6.  
  7. strFrom = 'axxx@xx.xxxu'
  8. strTo = sys.argv[1]
  9.  
  10. theMessageText = """
  11. xxxx
  12. """
  13.  
  14. altText = """
  15. xxx
  16. """
  17.  
  18. # Create the root message and fill in the from, to, and subject headers
  19. msgRoot = MIMEMultipart('related')
  20. msgRoot['Subject'] = 'subject'
  21. msgRoot['From'] = strFrom
  22. msgRoot['To'] = strTo
  23. msgRoot['Cc'] = 'x@xxx.xx'
  24. msgRoot.preamble = 'This is a multi-part message in MIME format.'
  25.  
  26. # Encapsulate the plain and HTML versions of the message body in an
  27. # 'alternative' part, so message agents can decide which they want to display.
  28. msgAlternative = MIMEMultipart('alternative')
  29. msgRoot.attach(msgAlternative)
  30.  
  31. msgText = MIMEText(altText)
  32. msgAlternative.attach(msgText)
  33.  
  34. # We reference the image in the IMG SRC attribute by the ID we give it below
  35. msgText = MIMEText(theMessageText, 'html')
  36. msgAlternative.attach(msgText)
  37.  
  38. # This example assumes the image is in the current directory
  39. #fp = open('xa.jpg', 'rb')
  40. #msgImage = MIMEImage(fp.read())
  41. #fp.close()
  42.  
  43. # Define the image's ID as referenced above
  44. #msgImage.add_header('Content-ID', '<image1>')
  45. #msgRoot.attach(msgImage)
  46.  
  47. # Send the email (this example assumes SMTP authentication is required)
  48. import smtplib
  49. smtp = smtplib.SMTP_SSL()
  50. smtp.connect('xxx.com')
  51. smtp.login('xxx', 'xxx')
  52. smtp.sendmail(strFrom, strTo, msgRoot.as_string())
  53. smtp.quit()
  54.  
  55. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement