Reputation: 685
I'm trying to send an attachment with this Python code to send emails via Outlook.
The code at the moment looks like this and it works to send text msg, but my Eexcel file is not attaching.
import win32com.client
olMailItem = 0x0
obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.Subject = "test"
newMail.Body = "123"
newMail.To = "[email protected]"
attachment1 = "C:/Users/myuser/Desktop/aaa.xls"
newMail.Send()
Upvotes: 0
Views: 623
Reputation: 12499
Also Attachment Path Use r
so the string is treated as a raw string.
Example
attachment1 = r"C:/Users/myuser/Desktop/aaa.xls"
newMail.Attachments.Add(attachment1)
https://docs.python.org/3/reference/lexical_analysis.html#string-literals
Upvotes: 0
Reputation: 66215
You never actually attach a file - add a line like
newMail.Attachments.Add(attachment1)
Upvotes: 1