I use a batch file to run to open and close Outlook. After opening, how to open an email, and click on the download button using python ‘import win32com.client’ library? any suggestions?
I was able to download the attachment from the email, however they stopped sending the file as an attachment, but now the download link instead..
<code>import datetime
import os
import win32com.client
from pathlib import Path
</code>
<code>import datetime
import os
import win32com.client
from pathlib import Path
</code>
import datetime
import os
import win32com.client
from pathlib import Path
<code>home = str(Path.home())path = 'where to download'
</code>
<code>home = str(Path.home())path = 'where to download'
</code>
home = str(Path.home())path = 'where to download'
<code>outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") #opens outlookinbox = outlook.GetDefaultFolder(6)messages = inbox.Items
</code>
<code>outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") #opens outlookinbox = outlook.GetDefaultFolder(6)messages = inbox.Items
</code>
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") #opens outlookinbox = outlook.GetDefaultFolder(6)messages = inbox.Items
<code>def saveattachemnts(subject):for message in messages:if message.Subject == subject and message.Unread:#if message.Unread: #I usually use this because the subject line contains time and it varies over time. So I just use unread
</code>
<code>def saveattachemnts(subject):for message in messages:if message.Subject == subject and message.Unread:#if message.Unread: #I usually use this because the subject line contains time and it varies over time. So I just use unread
</code>
def saveattachemnts(subject):for message in messages:if message.Subject == subject and message.Unread:#if message.Unread: #I usually use this because the subject line contains time and it varies over time. So I just use unread
<code> # body_content = message.body
attachments = message.Attachments
attachment = attachments.Item(1)
for attachment in message.Attachments:
attachment.SaveAsFile(os.path.join(path, str(attachment)))
if message.Subject == subject and message.Unread:
message.Unread = False
break
</code>
<code> # body_content = message.body
attachments = message.Attachments
attachment = attachments.Item(1)
for attachment in message.Attachments:
attachment.SaveAsFile(os.path.join(path, str(attachment)))
if message.Subject == subject and message.Unread:
message.Unread = False
break
</code>
# body_content = message.body
attachments = message.Attachments
attachment = attachments.Item(1)
for attachment in message.Attachments:
attachment.SaveAsFile(os.path.join(path, str(attachment)))
if message.Subject == subject and message.Unread:
message.Unread = False
break
<code>saveattachemnts('Scheduled Report BI Report - All NPIs - Active and Net New NPIs (Do Not Edit): You have received a new report')
</code>
<code>saveattachemnts('Scheduled Report BI Report - All NPIs - Active and Net New NPIs (Do Not Edit): You have received a new report')
</code>
saveattachemnts('Scheduled Report BI Report - All NPIs - Active and Net New NPIs (Do Not Edit): You have received a new report')
New contributor
Brian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.