Skip to content

Instantly share code, notes, and snippets.

@bngsudheer
Created June 25, 2011 07:59
Show Gist options
  • Save bngsudheer/1046277 to your computer and use it in GitHub Desktop.
Save bngsudheer/1046277 to your computer and use it in GitHub Desktop.
Python SMTP Example
#!/usr/bin/evn python
from smtplib import SMTP
from email.MIMEText import MIMEText
try:
msg = MIMEText("body", "subject is this")
msg['Subject']= 'subject is this'
msg['From'] = 'sender@example.com'
conn = SMTP("mail.example.com")
conn.set_debuglevel(False)
conn.login('username@example.com', 'password')
for to_email in to_emails:
conn.sendmail('sender@example.com', 'recipient@example.com', msg.as_string())
conn.close()
except Exception, e:
print "mail failed; %s" % str(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment