forked from paramiao/pyMail
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
添加docstring和删除邮件api,并引入logging模块方便调试。
- Loading branch information
firemiles
committed
Mar 9, 2015
1 parent
305065e
commit 7c5f793
Showing
4 changed files
with
224 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pyc |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.