python2.7发送邮件失败之——代码问题
2024-09-08 14:04:26
使用python2.7发送邮件,代码如下:
from email.header import Header
from email.mime.text import MIMEText
import smtplib
#发送邮箱
sender='yq_test@126.com'
password='123456'
#接受邮箱
receiver='41618174@qq.com'
smtpserver='smtp.126.com'
subject='python email test'
msg=MIMEText('下雨了,大家关好窗户','plain','utf-8')
msg['Subject']=Header(subject,'utf-8')
try:
smtp=smtplib.SMTP()
smtp.connect(smtpserver)
smtp.login(sender,password)
smtp.sendmail(sender,receiver,msg.as_string())
smtp.quit()
print "邮件发送成功"
except smtplib.SMTPException:
print "Error:无法发邮件"
运行时提示:
Error:无法发邮件
<class 'smtplib.SMTPException'>
解决办法:
在try的上面加上以下两行代码,问题解决:
msg['From']=sender
msg['to']=receiver
各位看官,看完后不要忘了为我乐于分享的精神点个赞哦
最新文章
- matlab中数组创建方法
- JavaScript深入浅出2-表达式和运算符
- flex lineChart 显示所有的数据节点
- No.3__C#
- C# 字符串替换Replace
- 轻量级模块化开发框架 Hasor 核心模块 v0.0.2 发布
- angular2怎么使用第三方的库(jquery等)
- hadoop-1.2.1伪分布模式配置
- 自定义tableViewCell
- PHP_string
- Linux驱动设计——内存与IO访问
- HDU 3555 Bomb 数位dp
- Go 解析JSON
- 开始AFNetworking
- awk学习总结(两) How awk works and awk CMD in a file
- 1637: [Usaco2007 Mar]Balanced Lineup
- net core appsetting配置
- java学习教程与笔记
- Vue对Html标签应用条件渲染
- Shell脚本编程(二):shell变量
热门文章
- selenium 控制窗口无限向下滚动
- BJD4th pwn pi
- 任务日历关联(Project)
- response.setHeader(";xxx";,";大侠";)如果赋值中文,那么将不会在页面出值,
- JAVA获取昨天、今天、明天等日期
- Windows库函数获取 可执行程序所在路径
- 【LeetCode】940. Distinct Subsequences II 解题报告(Python)
- 【LeetCode】641. Design Circular Deque 解题报告(Python & C++)
- 【LeetCode】228. Summary Ranges 解题报告(Python)
- VUE3 之 循环渲染