/Doc/includes/email-simple.py

http://unladen-swallow.googlecode.com/ · Python · 24 lines · 11 code · 4 blank · 9 comment · 0 complexity · 98aa512a1ff0bf401771d9203f3294a1 MD5 · raw file

  1. # Import smtplib for the actual sending function
  2. import smtplib
  3. # Import the email modules we'll need
  4. from email.mime.text import MIMEText
  5. # Open a plain text file for reading. For this example, assume that
  6. # the text file contains only ASCII characters.
  7. fp = open(textfile, 'rb')
  8. # Create a text/plain message
  9. msg = MIMEText(fp.read())
  10. fp.close()
  11. # me == the sender's email address
  12. # you == the recipient's email address
  13. msg['Subject'] = 'The contents of %s' % textfile
  14. msg['From'] = me
  15. msg['To'] = you
  16. # Send the message via our own SMTP server, but don't include the
  17. # envelope header.
  18. s = smtplib.SMTP()
  19. s.sendmail(me, [you], msg.as_string())
  20. s.quit()