send-test-email.py 620 B

12345678910111213141516171819202122232425262728
  1. import smtplib
  2. import sys
  3. if len(sys.argv) != 4:
  4. print "Usage %s [from] [to] [subject]"
  5. sys.exit(10)
  6. from_addr=sys.argv[1]
  7. to_addr=sys.argv[2]
  8. subject=sys.argv[3]
  9. # Import the email modules we'll need
  10. from email.mime.text import MIMEText
  11. # Create a text/plain message
  12. msg = MIMEText("Test email")
  13. # me == the sender's email address
  14. # you == the recipient's email address
  15. msg['Subject'] = subject
  16. msg['From'] = from_addr
  17. msg['To'] = to_addr
  18. # Send the message via our own SMTP server, but don't include the
  19. # envelope header.
  20. s = smtplib.SMTP('localhost')
  21. s.sendmail(from_addr, to_addr, msg.as_string())
  22. s.quit()