{"id":117361,"date":"2018-09-04T08:41:25","date_gmt":"2018-09-04T00:41:25","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=117361"},"modified":"2018-08-27T14:43:18","modified_gmt":"2018-08-27T06:43:18","slug":"python-outlook-read","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/python-outlook-read.html","title":{"rendered":"\u4f7f\u7528 Python \u8bfb\u53d6 Outlook \u4e2d\u7535\u5b50\u90ae\u4ef6\u7684\u65b9\u6cd5"},"content":{"rendered":"

\u4ece\u4e8b\u7535\u5b50\u90ae\u4ef6\u8425\u9500\uff0c\u51c6\u5165opt-in\u90ae\u7bb1\u5217\u8868\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u3002\u4f60\u53ef\u80fd\u5df2\u7ecf\u6709\u4e86\u51c6\u5165\u5217\u8868\uff0c\u540c\u65f6\u8fd8\u4f7f\u7528\u7535\u5b50\u90ae\u4ef6\u5ba2\u6237\u7aef\u8f6f\u4ef6\u3002\u5982\u679c\u4f60\u80fd\u4ece\u7535\u5b50\u90ae\u4ef6\u5ba2\u6237\u7aef\u4e2d\u5bfc\u51fa\u51c6\u5165\u5217\u8868\uff0c\u90a3\u8fd9\u4efd\u5217\u8868\u60f3\u5fc5\u662f\u6781\u597d\u7684\u3002<\/p>\n

\u6211\u4f7f\u7528\u4e00\u4e9b\u4ee3\u7801\u6765\u5c06 outlook \u914d\u7f6e\u4e2d\u7684\u6240\u6709\u90ae\u4ef6\u5199\u5165\u4e00\u4e2a\u4e34\u65f6\u6587\u4ef6\u4e2d\uff0c\u73b0\u5728\u8ba9\u6211\u6765\u5c1d\u8bd5\u89e3\u91ca\u4e00\u4e0b\u8fd9\u4e9b\u4ee3\u7801\u3002<\/p>\n

\u9996\u5148\u4f60\u9700\u8981\u5bfc\u5165 win32com.client\uff0c\u4e3a\u6b64\u4f60\u9700\u8981\u5b89\u88c5 pywin32\uff1a<\/p>\n

pip install pywin32<\/pre>\n

\u6211\u4eec\u9700\u8981\u901a\u8fc7 MAPI \u534f\u8bae\u8fde\u63a5 Outlok\uff1a<\/p>\n

outlook=win32com.client.Dispatch(\"Outlook.Application\").GetNamespace(\"MAPI\")<\/pre>\n

\u7136\u540e\u4ece outlook \u914d\u7f6e\u4e2d\u83b7\u53d6\u6240\u6709\u7684\u8d26\u6237\uff1a<\/p>\n

accounts= win32com.client.Dispatch(\"Outlook.Application\").Session.Accounts;<\/pre>\n

\u5728\u7136\u540e\u9700\u8981\u4ece\u540d\u4e3a emaileri_al \u7684\u6536\u4ef6\u7bb1\u4e2d\u83b7\u53d6\u90ae\u4ef6\uff1a<\/p>\n

def emailleri_al(folder):\r\nmessages = folder.Items\r\na=len(messages)\r\nif a>0:\r\nfor message2 in messages:\r\ntry:\r\nsender = message2.SenderEmailAddress\r\nif sender != \"\":\r\nprint(sender, file=f)\r\nexcept:\r\nprint(\"Ben hatay\u0131m\")\r\nprint(account.DeliveryStore.DisplayName)\r\npass\r\ntry:\r\nmessage2.Save\r\nmessage2.Close(0)\r\nexcept:\r\npass<\/pre>\n

\u4f60\u9700\u8981\u8fdb\u5165\u6240\u6709\u8d26\u6237\u7684\u6240\u6709\u6536\u4ef6\u7bb1\u4e2d\u83b7\u53d6\u7535\u5b50\u90ae\u4ef6\uff1a<\/p>\n

for account in accounts:\r\nglobal inbox\r\ninbox = outlook.Folders(account.DeliveryStore.DisplayName)\r\nprint(\"****Account Name**********************************\",file=f)\r\nprint(account.DisplayName,file=f)\r\nprint(account.DisplayName)\r\nprint(\"***************************************************\",file=f)\r\nfolders = inbox.Folders\r\nfor folder in folders:\r\nprint(\"****Folder Name**********************************\", file=f)\r\nprint(folder, file=f)\r\nprint(\"*************************************************\", file=f)\r\nemailleri_al(folder)\r\na = len(folder.folders)\r\nif a>0 :\r\nglobal z\r\nz = outlook.Folders(account.DeliveryStore.DisplayName).Folders(folder.name)\r\nx = z.Folders\r\nfor y in x:\r\nemailleri_al(y)\r\nprint(\"****Folder Name**********************************\", file=f)\r\nprint(\"...\"+y.name,file=f)\r\nprint(\"*************************************************\", file=<\/pre>\n

\u4e0b\u9762\u662f\u5b8c\u6574\u7684\u4ee3\u7801\uff1a<\/p>\n

import win32com.client\r\nimport win32com\r\nimport os\r\nimport sys\r\nf = open(\"testfile.txt\",\"w+\")\r\noutlook = win32com.client.Dispatch(\"Outlook.Application\").GetNamespace(\"MAPI\")\r\naccounts= win32com.client.Dispatch(\"Outlook.Application\").Session.Accounts;\r\ndef emailleri_al(folder):\r\nmessages = folder.Items\r\na=len(messages)\r\nif a>0:\r\nfor message2 in messages:\r\ntry:\r\nsender = message2.SenderEmailAddress\r\nif sender != \"\":\r\nprint(sender, file=f)\r\nexcept:\r\nprint(\"Error\")\r\nprint(account.DeliveryStore.DisplayName)\r\npass\r\ntry:\r\nmessage2.Save\r\nmessage2.Close(0)\r\nexcept:\r\npass\r\nfor account in accounts:\r\nglobal inbox\r\ninbox = outlook.Folders(account.DeliveryStore.DisplayName)\r\nprint(\"****Account Name**********************************\",file=f)\r\nprint(account.DisplayName,file=f)\r\nprint(account.DisplayName)\r\nprint(\"***************************************************\",file=f)\r\nfolders = inbox.Folders\r\nfor folder in folders:\r\nprint(\"****Folder Name**********************************\", file=f)\r\nprint(folder, file=f)\r\nprint(\"*************************************************\", file=f)\r\nemailleri_al(folder)\r\na = len(folder.folders)\r\nif a>0 :\r\nglobal z\r\nz = outlook.Folders(account.DeliveryStore.DisplayName).Folders(folder.name)\r\nx = z.Folders\r\nfor y in x:\r\nemailleri_al(y)\r\nprint(\"****Folder Name**********************************\", file=f)\r\nprint(\"...\"+y.name,file=f)\r\nprint(\"*************************************************\", file=f)\r\nprint(\"Finished Succesfully\")<\/pre>\n

via:\u00a0https:\/\/www.codementor.io\/aliacetrefli\/how-to-read-outlook-emails-by-python-jkp2ksk95<\/a><\/p>\n

\u4f5c\u8005\uff1aA.A. Cetrefli<\/a>\u00a0\u9009\u9898\uff1alujun9972<\/a>\u00a0\u8bd1\u8005\uff1alujun9972<\/a>\u00a0\u6821\u5bf9\uff1awxy<\/a><\/p>\n

\u672c\u6587\u7531\u00a0LCTT<\/a>\u00a0\u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd<\/a>\u00a0\u8363\u8a89\u63a8\u51fa<\/p>\n

 <\/p>\n

\n

\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/linux.cn\/article-9948-1.html<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1a https:\/\/lrxjmw.cn\/python-outlook-read.html \u200e<\/a>\u7f16\u8f91\uff1a\u5f20\u5efa\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u4ece\u4e8b\u7535\u5b50\u90ae\u4ef6\u8425\u9500\uff0c\u51c6\u5165opt-in\u90ae\u7bb1\u5217\u8868\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u3002\u4f60\u53ef\u80fd\u5df2\u7ecf\u6709\u4e86\u51c6\u5165\u5217\u8868\uff0c\u540c\u65f6\u8fd8\u4f7f\u7528\u7535\u5b50\u90ae\u4ef6\u5ba2\u6237\u7aef\u8f6f\u4ef6\u3002 […]<\/p>\n","protected":false},"author":1890,"featured_media":117362,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-117361","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/117361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1890"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=117361"}],"version-history":[{"count":6,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/117361\/revisions"}],"predecessor-version":[{"id":117812,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/117361\/revisions\/117812"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/117362"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=117361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=117361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=117361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}