# encoding: utf-8
from email.mime.text import MIMEText
import smtplib
# server conf
host = "smtp.qq.com"
user = "qs9816"
password = "password"
postfix = "qq.com"
mail_to_user = ["qs9816@qq.com"]
def sendmail(touser, subject, content):
""" test """
fromuser = user + "<" + user + "@" + postfix
msg = MIMEText(content)
msg['Subject'] = subject
msg['From'] = fromuser
msg['To'] = ";".join(touser)
try:
server = smtplib.SMTP()
server.connect(host)
server.login(user, password)
server.sendmail(fromuser, touser, msg.as_string())
server.close()
return True
except Exception, e:
print str(e)
return False
if __name__ == '__main__':
if sendmail(mail_to_user, "test", "testttttttttttttttt"):
print "succ"
else:
print "fail"
python 发送邮件
最新推荐文章于 2024-03-05 10:38:34 发布
本文介绍了一个简单的Python脚本,该脚本使用smtplib和email.mime.text模块来发送电子邮件。通过配置SMTP服务器、用户名、密码等信息,可以实现从指定邮箱发送纯文本邮件到目标邮箱地址。

4807

被折叠的 条评论
为什么被折叠?



