forked from paramiao/pyMail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
29 lines (27 loc) · 962 Bytes
/
example.py
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
# -*- coding: utf-8 -*
import pyMail
#初始化接收邮件类
rml = pyMail.ReceiveMailDealer('mail_address','mail_pwd','imap.gmail.com')
rml.select('INBOX')
#获取未读邮件列表
print(rml.getUnread())#('OK',['1 2 3 4'])
#遍历未读邮件
for num in rml.getUnread()[1][0].split(' '):
if num != '':
mailInfo = rml.getMailInfo(num)
print(mailInfo['subject'])
print(mailInfo['body'])
print(mailInfo['html'])
print(mailInfo['from'])
print(mailInfo['to'])
#遍历附件列表
for attachment in mailInfo['attachments']:
fileob = open(attachment['name'],'wb')
fileob.write(attachment['data'])
fileob.close()
#初始化发送邮件类
sml = pyMail.SendMailDealer('mail_address','mail_pwd','smtp.gmail.com', 587)
#设置邮件信息
sml.setMailInfo('[email protected]','测试','正文','plain','/home/paramiao/resume.html')
#发送邮件
sml.sendMail()