用Python自动发送最基本的邮件(主题+收件人)
邮件形式 | 内容 |
---|---|
最基本 | 收件人+主题 |
最常用 | 收件人+主题+正文 |
一般流程申请邮件 | 收件人+主题+正文+抄送 |
发报表邮件 | 收件人+主题+抄送+附件 |
加说明报表邮件 | 收件人+主题+正文+抄送+附件 |
import zmail
zmail.server('[email protected]','password').send_mail('[email protected]',{
'subject':'我是你的舔狗1号'})
女神
import zmail
zmail.server('[email protected]','password').send_mail([('女神','[email protected]')],{
'subject':'我是你的舔狗1号'})
作业:把收件人外显名改成
美国队长
import zmail
zmail.server('[email protected]','password',smtp_host='smtp.263.net',smtp_port=25).send_mail('[email protected]',{
'subject':'我是你的舔狗1号'})
import requests
import json
import zmail
response = requests.get('https://api.uomg.com/api/rand.qinghua')
tiangou = json.loads(response.text)['content']
zmail.server('[email protected]','password').send_mail('[email protected]',{
'subject':tiangou})
用Python自动发送最常用的邮件(主题+收件人+正文+抄送)
import zmail
mail = dict(
subject='今日数据情况',
content_text='今日新录入名片100张,有效添加50张,添加率为50%'
)
zmail.server('[email protected]','password').send_mail('[email protected]',mail)
在此基础上,重点突出添加率
带格式的正文
import zmail
mail = dict(
subject='今日数据情况',
content_html='今日新录入名片100张,有效添加50张,添加率为50%'
)
zmail.server('[email protected]','password').send_mail('[email protected]',mail)
注:需要额外的HTML基础知识
如果有很多个收件人的时候
import zmail
mail = dict(
subject='今日数据情况',
content_text='今日新录入名片100张,有效添加50张,添加率为50%'
)
zmail.server('[email protected]','password').send_mail(['[email protected]','[email protected]'],mail)
可能还要抄送老大
import zmail
mail = dict(
subject='今日数据情况',
content_text='今日新录入名片100张,有效添加50张,添加率为50%'
)
zmail.server('[email protected]','password').send_mail('[email protected]',mail,cc='[email protected]')
作业:给抄送人也改一个别名,改成
天山大佬
用Python自动发送最常用的邮件(主题+收件人+正文+附件)
import zmail
mail = dict(
subject='今日数据情况',
content_text='今日新录入名片100张,有效添加50张,添加率为50%.各组详情请见附件',
attachments=r'E:\Onedrive\桌面\报表.xlsx'
)
zmail.server('[email protected]','password').send_mail('[email protected]',mail)
如果有多个附件,代码如下
import zmail
mail = dict(
subject='今日数据情况',
content_text='今日新录入名片100张,有效添加50张,添加率为50%.各组详情请见附件报表2',
attachments=[r'E:\Onedrive\桌面\报表1.xlsx',r'E:\Onedrive\桌面\报表2.xlsx']
)
zmail.server('[email protected]','password').send_mail('[email protected]',mail)
作业:写一份完整的邮件代码,包含以下内容
- 多个收件人,收件人都外显为姓名
- 多个抄送人,也带上自己名字
- 多个附件,并在正文中注明附件作用
- 带格式的正文:附件名使用斜体,添加率使用加粗,领导名字使用红色加粗字体显示
- 主题变成一个自动带上当天日期的内容