发布时间:2019-08-13 07:39:58编辑:auto阅读(1924)
参考链接:How do I send mail from a Python script?
使用linux下的sendmail程序来发送邮件,利用popen函数(python docs关于popen函数)可以直接调用linux系统程序,需要指定程序所在的位置。
#!/usr/bin/python
# -*- coding: UTF-8 -*-
#Author: Victor Lv
SENDMAIL = "/usr/sbin/sendmail" #sendmail(可执行程序)所在的路径
sender = "sender@example.com"
receivers = ["user1@example.com", "user2@example.com"]
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 PuLP and Glpk
下一篇: Python循环语句
50495
49799
40396
37417
31835
28696
27628
22413
22412
20727
482°
1100°
900°
835°
1081°
957°
1570°
2939°
2618°
2013°