日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 读取outlook_如何用 Python 读取 Outlook 中的电子邮件

發布時間:2023/12/10 python 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 读取outlook_如何用 Python 读取 Outlook 中的电子邮件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

從事電子郵件營銷, 準入(opt-in)郵箱列表是必不可少的。你可能已經有了準入列表,同時還使用電子郵件客戶端軟件。如果你能從電子郵件客戶端中導出準入列表,那這份列表想必是極好的。

我使用一些代碼來將 outlook 配置中的所有郵件寫入一個臨時文件中,現在讓我來嘗試解釋一下這些代碼。

首先你需要導入 win32com.client,為此你需要安裝 pywin32:

pip install pywin32

我們需要通過 MAPI 協議連接 Outlok:

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")

然后從 outlook 配置中獲取所有的賬戶:

accounts= win32com.client.Dispatch("Outlook.Application").Session.Accounts;

在然后需要從名為 emaileri_al 的收件箱中獲取郵件:

def emailleri_al(folder):

messages = folder.Items

a=len(messages)

if a>0:

for message2 in messages:

try:

sender = message2.SenderEmailAddress

if sender != "":

print(sender, file=f)

except:

print("Ben hatay?m")

print(account.DeliveryStore.DisplayName)

pass

try:

message2.Save

message2.Close(0)

except:

pass

你需要進入所有賬戶的所有收件箱中獲取電子郵件:

for account in accounts:

global inbox

inbox = outlook.Folders(account.DeliveryStore.DisplayName)

print("****Account Name**********************************",file=f)

print(account.DisplayName,file=f)

print(account.DisplayName)

print("***************************************************",file=f)

folders = inbox.Folders

for folder in folders:

print("****Folder Name**********************************", file=f)

print(folder, file=f)

print("*************************************************", file=f)

emailleri_al(folder)

a = len(folder.folders)

if a>0 :

global z

z = outlook.Folders(account.DeliveryStore.DisplayName).Folders(folder.name)

x = z.Folders

for y in x:

emailleri_al(y)

print("****Folder Name**********************************", file=f)

print("..."+y.name,file=f)

print("*************************************************", file=

下面是完整的代碼:

import win32com.client

import win32com

import os

import sys

f = open("testfile.txt","w+")

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")

accounts= win32com.client.Dispatch("Outlook.Application").Session.Accounts;

def emailleri_al(folder):

messages = folder.Items

a=len(messages)

if a>0:

for message2 in messages:

try:

sender = message2.SenderEmailAddress

if sender != "":

print(sender, file=f)

except:

print("Error")

print(account.DeliveryStore.DisplayName)

pass

try:

message2.Save

message2.Close(0)

except:

pass

for account in accounts:

global inbox

inbox = outlook.Folders(account.DeliveryStore.DisplayName)

print("****Account Name**********************************",file=f)

print(account.DisplayName,file=f)

print(account.DisplayName)

print("***************************************************",file=f)

folders = inbox.Folders

for folder in folders:

print("****Folder Name**********************************", file=f)

print(folder, file=f)

print("*************************************************", file=f)

emailleri_al(folder)

a = len(folder.folders)

if a>0 :

global z

z = outlook.Folders(account.DeliveryStore.DisplayName).Folders(folder.name)

x = z.Folders

for y in x:

emailleri_al(y)

print("****Folder Name**********************************", file=f)

print("..."+y.name,file=f)

print("*************************************************", file=f)

print("Finished Succesfully")

本文由 LCTT 原創編譯,Linux中國 榮譽推出

總結

以上是生活随笔為你收集整理的python 读取outlook_如何用 Python 读取 Outlook 中的电子邮件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。