python ------ 自动发送邮件
来源:互联网 发布:java工程反编译 编辑:程序博客网 时间:2024/05/18 00:55
测试环境:
python3.4
发件服务器 网易yeah
收件服务器 移动139邮箱
注意:一定要在发件的邮箱里面设置POP3/SMTP/IMAP为开启状态,要不然会报错:
535 Error:authentication failed
通过本程序,可以自动给自己的手机邮箱发送邮件,在手机邮箱中把发件地址设置为白名单,就可以在手机收到短信通知
测试结果如图:
import smtplibimport emailfrom email.mime.text import MIMEText#配置信息send_mail_host = "smtp.yeah.net" # 发送的smtpsend_mail_user = "*******" #发件人邮箱的用户名send_mail_user_name = "李啊涌" #发件人姓名send_mail_pswd = "********" #发件邮箱设置的授权码send_mail_postfix = "yeah.net" # 发邮件的域名get_mail_user = "***********" #收件用户名get_mail_postfix = "139.com" #收件人邮箱服务器get_mail_host = "pop.139.com" #收件人pop3服务器def semd_mail(sub, content): send_mail_address = send_mail_user_name + "<" + send_mail_user + "@" + send_mail_postfix + ">" msg = email.mime.text.MIMEText(content) msg['Subject'] = sub msg['From'] = send_mail_address msg['to'] = to_adress = "139SMSserver<" + get_mail_user + "@" + get_mail_postfix + ">" try: stp = smtplib.SMTP() stp.connect(send_mail_host) stp.login(send_mail_user, send_mail_pswd) stp.sendmail(send_mail_address, to_adress, msg.as_string()) stp.close() return True except Exception as e: print( e) return Falseif __name__ == '__main__': sub="测试" #主题 content="python如此强大!" #发件内容 if semd_mail(sub, content): print ("发送成功") else: print( '发送失败')
0 0
- python自动发送邮件
- python ------ 自动发送邮件
- python邮件自动发送
- Python自动发送邮件
- python 邮件自动发送客户端
- Python(8) 自动发送邮件
- 使用python自动发送邮件
- 利用Python自动发送邮件
- Python--脚本自动发送邮件
- python邮件随机自动发送器
- 【Python学习笔记】-自动发送邮件脚本
- python自动发送报警监控邮件
- Python使用SMTP自动发送邮件
- 自动邮件发送程序Python版本
- Python自动发送邮件的脚本源码
- python 自动发送邮件发送多人、群发、多附件
- 自动发送邮件
- 自动发送邮件
- 740C.Alyona and mex codeforces
- App引导页面的常用布局和实现
- 正则中\\b和\\B的区别及注意事项
- std::copy() & std::back_inserter()
- 应对冒充者综合症
- python ------ 自动发送邮件
- nodejs Async 详解
- LCM Walk HDU
- 详解PHP的执行原理和流程
- 蔬菜大棚控制与WEB
- 数组复制
- 事件分发学习笔记二(ViewGroup篇)
- Triangle
- 计数排序