Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from email.utils import parseaddr, formataddr
def _format_addr(s):
name, addr = parseaddr(s)
return formataddr(( \
Header(name, 'utf-8').encode(), \
addr.encode('utf-8') if isinstance(addr, unicode) else addr))
from_addr = '***@***.com'
mail_account = '***@***.com'
mail_password = '****'
to_addr = ['****']
mail_Subject = 'test python smtplib'
msg_content = 'test python smtplib'
msg = MIMEText(msg_content, 'html', 'utf-8')
msg['From'] = _format_addr(from_addr)
msg['To'] = _format_addr(to_addr)
msg['Subject'] = _format_addr(mail_Subject)
smtp_server = ''
smtp_port = 465
server = smtplib.SMTP_SSL(smtp_server, smtp_port)
server.login(mail_account, mail_password)
server.sendmail(from_addr, to_addr, msg.as_string())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.