Skip to content

Commit

Permalink
添加docstring和删除邮件api,并引入logging模块方便调试。
Browse files Browse the repository at this point in the history
  • Loading branch information
firemiles committed Mar 9, 2015
1 parent 305065e commit 7c5f793
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 115 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
Empty file added __init__.py
Empty file.
55 changes: 35 additions & 20 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*
import pyMail
import getpass
import time
# 推荐使用qq邮箱
username = raw_input("User: ")
passwd = getpass.getpass()
smtp_server = raw_input("smtp server: ")
imap_server = raw_input("imap server: ")

#初始化接收邮件类
rml = mailUtils.ReceiveMailDealer('mail_address','mail_pwd','imap.gmail.com')
# 初始化发送邮件类
sml = pyMail.SendMailDealer(username, passwd, smtp_server, 25)
# 设置邮件信息
sml.setMailInfo(username, u'标题', u'正文', 'plain', './README.md')
# 发送邮件
sml.sendMail()

# 初始化接收邮件类
rml = pyMail.ReceiveMailDealer(username, passwd, imap_server)
rml.select('INBOX')
#获取未读邮件列表
print rml.getUnread()#('OK',['1 2 3 4'])
#遍历未读邮件
# 延时2秒再读取邮件
time.sleep(2)
# 获取未读邮件列表
print(rml.getUnread())
#('OK',['1 2 3 4'])
# 遍历未读邮件
# print rml.search(None, 'ALL')
#()
for num in rml.getUnread()[1][0].split(' '):
if num != '':
if num != '':
mailInfo = rml.getMailInfo(num)
print mailInfo['subject']
print mailInfo['body']
print mailInfo['html']
print mailInfo['from']
print mailInfo['to']
#遍历附件列表
print(rml.delete([num]))
print(mailInfo['subject'])
print(mailInfo['body'])
print(mailInfo['html'])
print(mailInfo['from'])
print(mailInfo['to'])
print(mailInfo['attachments'])
# 遍历附件列表
for attachment in mailInfo['attachments']:
fileob = open(attachment['name'],'wb')
fileob = open(attachment['name'], 'wb')
fileob.write(attachment['data'])
fileob.close()

#初始化发送邮件类
sml = mailUtils.SendMailDealer('mail_address','mail_pwd','smtp.gmail.com')
#设置邮件信息
sml.setMailInfo('[email protected]','测试','正文','plain','/home/paramiao/resume.html')
#发送邮件
sml.sendMail()
Loading

0 comments on commit 7c5f793

Please sign in to comment.