美文网首页
python自动化办公——邮箱

python自动化办公——邮箱

作者: 刘年 | 来源:发表于2020-03-21 21:27 被阅读0次

1、安装模块

需要yagmail keyring schedule imbox 四个模块

2、邮箱开通IMAP/SMTP/POP3/SMTP服务

image.png

3、利用yagmail存储邮箱和密码

这样就不用每次都输入,容易被别人看到

import yagmail
yagmail.register('id','password')

4、发送第一封邮件

import yagmail
yag =yagmail.SMTP(user="xxx@126.com",host='smtp.126.com')
contents =[
    'hello',
    '这是一篇邮件',
]
#接受邮箱,可以多邮箱
yag.send('xxx@qq.com','第一封邮件',contents=contents)

真的是很方便

5、发送网页链接

可以设计内容,按照HTML格式

contents =[
    'hello',
    '这是一篇邮件',
    '<a href="">xx</a>'
]

6、发送附件

自动识别附件,将本地路径作为内容发出去即可

contents =[
    'hello',
    '这是一篇邮件',
    '<a href="">xx</a>',
    '图片.JPG'
]

7、正文中插入图片

contents =[
    'hello',
    '这是一篇邮件',
    '<a href="">xx</a>',
     yagmail,inline( '图片.JPG')
]

8、读取邮件

网易邮箱太麻烦,拦截太厉害,用qq邮箱方便一点

from imbox import Imbox
import keyring

#读取之前存储的密码
password = keyring.get_password('yagmail','xx@qq.com')
with Imbox('imap.qq.com','xx@qq.com',password=password,ssl=True) as imbox:
    all_inbox_messages =imbox.messages()
    for uid,message in all_inbox_messages:
        print(message.subject)
        print(message.body['plain'])

相关文章

网友评论

      本文标题:python自动化办公——邮箱

      本文链接:https://www.haomeiwen.com/subject/uoiuyhtx.html