Created
July 6, 2019 03:00
-
-
Save carlos-wong/7a70e3f9fa3cbedca39686d32faddd71 to your computer and use it in GitHub Desktop.
This file contains 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.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 = ['****@gmail.com'] | |
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.exmail.qq.com' | |
smtp_port = 465 | |
server = smtplib.SMTP_SSL(smtp_server, smtp_port) | |
server.set_debuglevel(1) | |
#server.starttls() | |
server.login(mail_account, mail_password) | |
server.sendmail(from_addr, to_addr, msg.as_string()) | |
server.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment