如何使用带有自定义主题行的python阅读电子邮件,然后运行存储过程

2024-09-25 02:34:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用下面的代码从不同的主题行获取电子邮件正文,然后我需要在Oracle中运行存储过程

假设我们收到这封带有特定主题行的邮件,我需要在我的Oracle数据库中插入9月9日的价格

 RIC    Date     Price
 Atul   9-Sep-19 298.14

这就是我迄今为止所尝试的

import win32com.client
import os
outlook=win32com.client.Dispatch("Outlook.Application").GetNameSpace("MAPI")
inbox=outlook.GetDefaultFolder(6).Folders.Item("MD-GPS") #Inbox default index value is 6
message=inbox.Items
for message2 in message:
        subject=message2.Subject
        print(subject)
        if 'EOD Level Report for ZKB Swisscanto' in subject:
            body=message2.body
            date=message2.senton.date()   
            sender=message2.Sender
            attachments=message2.Attachments
            print(subject)
            print(body)
            print(sender)
            print(attachments.count)
            print(date) 

Tags: inimportclientmessage主题fordatebody