#coding: Utf8from smtplib import smtp_sslfrom email.header import headerfrom email.mime.text import Mimetextmail_ info = {"from": "[email protected]", "to": "[email protected]", "hostname": "smtp.qq.com", "Usernam E ":" [email protected] "," password ":" xxx "," mail_subject ":" Test "," Mail_text ":" Hello, this is a test emai L, sended by py "," mail_encoding ":" Utf-8 "}if __name__ = = ' __main__ ': #这里使用SMTP_SSL就是默认使用465端口 smtp = Smtp_ssl (ma Il_info["hostname"]) Smtp.set_debuglevel (1)
Smtp.ehlo (mail_info["hostname"]) Smtp.login (mail_in fo["username"], mail_info["password"]) msg = Mimetext (mail_info["Mail_text"], "plain", mail_info["mail_encoding"]) m sg["Subject"] = Header (mail_info["Mail_subject"], mail_info["mail_encoding"]) msg["from"] = mail_info["from"] msg["t O "] = mail_info[" to "]
smtp.sendmail (mail_info[' from ', mail_info[" to "], msg.as_string ()) Smtp.quit ()
Python send mail script SSL 465 port