【发布时间】:2016-03-09 12:25:38
【问题描述】:
我打算解析我的整个电子邮件收件箱以查找主题为“production”的电子邮件,以便将电子邮件提取到 .txt 文件中以进行进一步解析。我已经成功地让 Python 在我的收件箱中找到每封电子邮件,因为我创建了显示电子邮件数量和相关电子邮件(主题为“生产”的电子邮件总数和电子邮件)的计数。我想知道是否通过 Python,我可以在 Outlook 文件夹之间移动电子邮件,因此从收件箱到 Outlook 中名为“生产”的文件夹。我当前的代码看起来像(包含一个 GUI 以成功满足我的课程要求):
from tkinter import *
import win32com.client
import sys
import os.path
save_path = 'D:/Test1/'
nGui=Tk()
title=nGui.title('Production Accolation')
geo=nGui.geometry
def homepage():
geo('250x150')
title
BtnSta=Button(text="Start", command=start,height=2,width=100,font = "Calibri 12 bold").pack()
BtnRep=Button(text="Report",command=report,height=2, width=100,font = "Calibri 12 bold").pack()
BtnExi=Button(text="Exit",fg="red",command=end, height=2,width=100,font = "Calibri 12 bold").pack()
nGui.mainloop()
def start():
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
message = messages.GetLast()
subject=message.Subject
emailcount=0
corrcount=0
misccount=0
for m in messages:
emailcount=emailcount+1
if m.Subject=="production":
corrcount=corrcount+1
email="outlookparse"
compemail=os.path.join(save_path, email+".txt")
file1=open(compemail,"w")
file1.write(message.body)
file1.close()
else:
misccount=misccount+1
print("Total Emails ",emailcount)
print("Production Emails ",corrcount)
print("Miscellaneous Emails ",misccount)
def report():
print("ok")
def end():
exit()
homepage()
【问题讨论】:
标签: python email winapi outlook directory