{"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>\nvia:\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