Skip to content

Instantly share code, notes, and snippets.

@zhwei
Last active August 29, 2015 14:16
Show Gist options
  • Save zhwei/1a622bb3ddaa3945f4e1 to your computer and use it in GitHub Desktop.
Save zhwei/1a622bb3ddaa3945f4e1 to your computer and use it in GitHub Desktop.
Python Send Mail
import smtplib
from email.utils import formataddr
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def send_mail(sender, alias, to, subject, body, msg_type='plain', reply_to=None):
msg = MIMEMultipart('alternative')
msg['From'] = formataddr((alias, sender))
msg['To'] = to
msg['Subject'] = subject
msg.add_header('reply-to', reply_to or sender)
msg.attach(MIMEText(body, msg_type))
s = smtplib.SMTP('smtp.gaotech.in')
s.sendmail(sender, to, msg.as_string())
s.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment