Update avaliable. Click RELOAD to update.
目录

Python使用smtplib库测试发送邮件

Python使用smtplib库测试发送邮件

如果你想编写一个简单的邮件测试客户端,python是个好工具,越发觉得python真是简单高效。下面是一个简单的python邮件客户端代码的实现。

from smtplib import SMTP_SSL
from email.header import Header
from email.mime.text import MIMEText

mail_info = {
	"from" : "[email protected]",
	"to" : "[email protected]",
	"hostname" : "smtp.163.com",
	"username" : "[email protected]",
	"password" : "xxxxxxxxx",
	"mail_subject" : "python mail test",
	"mail_text" : "Hello World",
	"mail_encoding" : "utf-8"
}

if __name__ == '__main__':
	smtp = SMTP_SSL(mail_info["hostname"])
	smtp.set_debuglevel(1)

	smtp.ehlo(mail_info["hostname"])
	smtp.login(mail_info["username"], mail_info["password"])

	msg = MIMEText(mail_info["mail_text"], "plain", mail_info["mail_encoding"])
	msg["Subject"] = Header(mail_info["mail_subject"], mail_info["mail_encoding"])
	msg["from"] = mail_info["from"]
	msg["to"] = mail_info["to"]

	smtp.sendmail(mail_info["from"], mail_info["to"], msg.as_string())

	smtp.quit()
版权所有,本作品采用知识共享署名-非商业性使用 3.0 未本地化版本许可协议进行许可。转载请注明出处:https://www.wangjun.dev//2016/02/python-smtplib-mail/

Related posts