linux下python使用sendmail发送邮件
本文实例为大家分享了python使用sendmail发送邮件的具体代码,供大家参考,具体内容如下
参考链接:How do I send mail from a Python script?
使用linux下的sendmail程序来发送邮件,利用popen函数(python docs关于popen函数)可以直接调用linux系统程序,需要指定程序所在的位置。
python代码:
#!/usr/bin/python # -*- coding: UTF-8 -*- #Author: Victor Lv SENDMAIL = "/usr/sbin/sendmail" #sendmail(可执行程序)所在的路径 sender = "[email protected]" receivers = ["[email protected]", "[email protected]"] subject = "这是邮件标题" text = "这是邮件正文。" #将这些元素组合成一条message message = """\ From: %s To: %s Subject: %s %s """ % (sender, ", ".join(receivers), subject, text) # Send the mail import os p = os.popen("%s -t -i" % SENDMAIL, "w") p.write(message) status = p.close() if status: print "Sendmail exit status", status
python docs中关于发送邮件的其他方法和例子:email: Examples
相关推荐
以梦为马不负韶华 2020-10-20
夜斗不是神 2020-11-17
huavhuahua 2020-11-20
Yasin 2020-11-16
xiaoseyihe 2020-11-16
千锋 2020-11-15
diyanpython 2020-11-12
chunjiekid 2020-11-10
wordmhg 2020-11-06
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
lhtzbj 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16