python发送邮件

简介:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
使用python调用第三方邮箱群发邮件
第三方邮件需要设置授权码这里是 163 邮箱,图上传不了。
设置 = = = >邮箱安全设置 = = = >客户端授权密码
 
 
代码部分:
 
#!/usr/bin/env python
#__*__coding:utf-8__*__
 
import  smtplib
from  email.mime.text  import  MIMEText as mimetext
from  email.mime.multipart  import  MIMEMultipart
 
#发件服务器地址
mail_host  =  'smtp.163.com'
#发件邮箱地址
sender_user  =  'xxxx_monitor@163.com'
#mail_pass = 'xxxxx'#登录密码
#邮箱授权码,不是登录密码
sender_pass  =  'xxxx'
#收件邮箱地址
receivers  =  [ 'receiver1@163.com' , 'receiver2@163.cn' ]
 
#邮件内容
message  =  mimetext( 'Python 邮件测试发送' , 'plain' , 'utf-8' )
#发送邮箱地址
message[ 'From' =  sender_user
#群发邮件时会报错message['To']不支持列表,使用join函数把地址合成字符串
message[ 'To' =   "," .join(receivers)
#邮件主题
subject  =  'Python SMTP 邮件测试'
message[ 'Subject' =  subject
# try:
#     smtpobj = smtplib.SMTP()
#     smtpobj.connect(mail_host,25)
#     smtpobj.login(mail_user,mail_pass)
#     smtpobj.sendmail(sender,receivers,message)
#     print '邮件发送成功'
# except:
#     print "邮件发送失败"
smtpobj  =  smtplib.SMTP()
smtpobj.connect(mail_host, 25 )
smtpobj.login(sender_user,sender_pass)
smtpobj.sendmail(sender_user,receivers,message.as_string())
smtpobj.close()










本文转自 wangpengtai  51CTO博客,原文链接:http://blog.51cto.com/wangpengtai/1950887,如需转载请自行联系原作者
目录
相关文章
|
7月前
|
前端开发 JavaScript Java
【实操】SpringBoot监听Iphone15邮件提醒,Selenium+Python自动化抢购脚本
本文介绍了一个结合SpringBoot和Python的实用功能,旨在监控iPhone 15的库存状态并通过邮件提醒用户。系统采用SpringBoot监听苹果官网API,解析JSON数据判断是否有货,并展示最近的库存记录。此外,还能自动触发Selenium+Python脚本实现自动化购买。文中详细介绍了技术栈、接口分析、邮件配置及自动化脚本的设置方法。该项目不仅适用于熟悉后端开发的人员,也适合回顾Layui和Jquery等前端技术。
89 0
【实操】SpringBoot监听Iphone15邮件提醒,Selenium+Python自动化抢购脚本
|
3月前
|
安全 API 文件存储
Yagmail邮件发送库:如何用Python实现自动化邮件营销?
本文详细介绍了如何使用Yagmail库实现自动化邮件营销。Yagmail是一个简洁强大的Python库,能简化邮件发送流程,支持文本、HTML邮件及附件发送,适用于数字营销场景。文章涵盖了Yagmail的基本使用、高级功能、案例分析及最佳实践,帮助读者轻松上手。
128 4
|
4月前
|
开发者 Python
使用Python实现自动化邮件通知:当长时程序运行结束时
本文介绍了如何使用Python实现自动化邮件通知功能,当长时间运行的程序完成后自动发送邮件通知。主要内容包括:项目背景、设置SMTP服务、编写邮件发送函数、连接SMTP服务器、发送邮件及异常处理等步骤。通过这些步骤,可以有效提高工作效率,避免长时间等待程序结果。
148 9
|
5月前
|
Python
python使用smtp发送邮件
python使用smtp发送邮件
72 0
|
7月前
|
数据安全/隐私保护 Python
如何使用Python自动发送邮件?
如何使用Python自动发送邮件?
185 1
|
8月前
|
监控 网络协议 网络安全
SMTP操作使用详解并通过python进行smtp邮件发送示例
SMTP操作使用详解并通过python进行smtp邮件发送示例
218 3
|
9月前
|
Python
python发送邮件
python发送邮件
71 1
|
9月前
|
数据安全/隐私保护 Python
如何使用 Python 发送邮件
如何使用 Python 发送邮件
|
9月前
|
网络安全 数据安全/隐私保护 Python
Python SMTP发送邮件
Python SMTP发送邮件
|
9月前
|
Windows Python
每日自动发邮件(Python +QQ邮箱 + Windows 10定时任务)
每日自动发邮件(Python +QQ邮箱 + Windows 10定时任务)
每日自动发邮件(Python +QQ邮箱 + Windows 10定时任务)

热门文章

最新文章