Last active
August 29, 2015 14:16
-
-
Save zhwei/1a622bb3ddaa3945f4e1 to your computer and use it in GitHub Desktop.
Python Send Mail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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