码迷,mamicode.com
首页 > 编程语言 > 详细

python实现简单的发送邮件

时间:2019-06-17 12:31:11      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:smtp   ssl   html   log   ring   print   服务   bsp   import   

import smtplib
from email.mime.text import MIMEText

smtpserver = "smtp.qq.com"
port =465
sender = "发件人账号@qq.com"
psw = "smtp服务的授权码"
receiver ="收件人账号@qq.com"
body = ‘<pre><h1> </h1></pre>‘

msg = MIMEText(body,‘html‘,"utf-8")
msg[‘from‘] = sender
msg[‘to‘] = receiver
msg[‘subject‘] = "发送的内容  "
try:
smtp = smtplib.SMTP_SSL(smtpserver, port)
smtp.login(sender, psw)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()
print(‘success‘)
except smtplib.SMTPException:
print(‘ERRO‘)

python实现简单的发送邮件

标签:smtp   ssl   html   log   ring   print   服务   bsp   import   

原文地址:https://www.cnblogs.com/wsfsd/p/11038869.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!