Skip to content

Instantly share code, notes, and snippets.

@muxueqz
Created December 21, 2012 02:16
Show Gist options
  • Save muxueqz/4350254 to your computer and use it in GitHub Desktop.
Save muxueqz/4350254 to your computer and use it in GitHub Desktop.
def send_mail(subject, content, address_from, address_to, smtp_host, smtp_user, smtp_password, smtp_port=25,using_tls=False, attachment=[]):
import smtplib
smtp = smtplib.SMTP()
# smtp = smtplib.SMTP(smtp_host)
is_gmail = False
if smtp_host == "smtp.gmail.com":
is_gmail = True
if is_gmail:
smtp_port = 587
smtp.connect(smtp_host, smtp_port)
if using_tls or is_gmail:
smtp.starttls()
smtp.ehlo() # must do while python is 2.5.x or lower.
# smtp.esmtp_features['auth'] = 'LOGIN DIGEST-MD5 PLAIN'
if smtp_user:
smtp.login(smtp_user, smtp_password)
mailbody = build_mail(subject, content, address_from, address_to, attachment=attachment)
smtp.sendmail(address_from, address_to.split(';'), mailbody.as_string())
smtp.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment