Python_操作邮箱
脚本:
from win32com.client import Dispatch
import datetime as date
import datetime
import re
import win32com.client, sqlite3
sub_today = '转发: 夸客数据导出'
att_KKYQHKJH = 'KKYQHKJH.xlsx'
att_KKYWSJ = 'KKYWSJ.xlsx'
outlook = Dispatch("Outlook.Application").GetNamespace("MAPI") --连接
inbox = outlook.GetDefaultFolder("6")
/*
OlFolderDeletedItems |
3 |
已删除邮件 |
OlFolderOutbox |
4 |
发件箱 |
OlFolderSentMail |
5 |
已发件邮件 |
olFolderInbox |
6 |
收件箱 |
OlFolderCalendar |
9 |
日历 |
OlFolderContacts |
10 |
联系人 |
olFolderJournal |
11 |
日记 |
olFolderNotes |
12 |
便笺 |
olFolderTasks |
13 |
任务 |
olFolderDrafts |
16 |
草稿 |
*/
begin = datetime.date.today() - datetime.timedelta(days=1)
end = begin + datetime.timedelta(days=1)
filter_string = "[receivedtime] >= '" + begin.strftime("%m/%d/%Y") + "' AND [receivedtime] <= '" + end.strftime("%m/%d/%Y") + "'"
print(filter_string)
print(begin,end)
items = inbox.Items.Restrict(filter_string)
for item in items:
if sub_today == item.Subject:
break
for att1 in item.Attachments:
if att1.FileName == att_KKYQHKJH:
att1.SaveAsFile('\\\\FTP.quarkfinance.com\\FTP folder\\催收数据目录\\HLXYD\\KKYQHKJH.xlsx ') ---保存地址
print(att_KKYQHKJH,item.receivedtime)
for att2 in item.Attachments:
if att2.FileName == att_KKYWSJ:
att2.SaveAsFile('\\\\FTP.quarkfinance.com\\FTP folder\\催收数据目录\\HLXYD\\KKYWSJ.xlsx ')
print(att_KKYWSJ,item.receivedtime)