发送邮件
#!/usr/bin/python#-*- coding: utf-8 -*-import smtplibfrom email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipartfrom email.header import Headersender = 'x@163.com'to = ["y
·
#!/usr/bin/python
#-*- coding: utf-8 -*-
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
sender = 'x@163.com'
to = ["y@qq.com", "z@qq.com"] # 多个收件人的写法
subject = 'From Python Email test'
smtpserver = 'smtp.163.com'
username = 'x'
password = 'passwordfa'
mail_postfix = '163.com'
contents = '这是一个Python的测试邮件,收到请勿回复,谢谢!!'
def send_mail(to_list, sub, content):
me = sender
msg = MIMEText(content, _subtype='plain', _charset='utf-8')
msg['Subject'] = subject
msg['From'] = me
msg['To'] = ";".join(to_list)
try:
server = smtplib.SMTP()
server.connect(smtpserver)
server.login(username, password)
server.sendmail(me, to_list, msg.as_string())
server.close()
return True
except Exception, e:
print str(e)
return False
if __name__ == '__main__':
if send_mail(to, subject, contents):
print "邮件发送成功! "
else:
print "失败!!!"
更多推荐
已为社区贡献5条内容
所有评论(0)