A simple example to send emails via Outlook and Python win32com.
import win32com.client s = win32com.client.Dispatch("Mapi.Session") o = win32com.client.Dispatch("Outlook.Application") s.Logon("Outlook2003") Msg = o.CreateItem(0) Msg.To = "recipient@domain.com" Msg.CC = "more email addresses here" Msg.BCC = "more email addresses here" Msg.Subject = "The subject of you mail" Msg.Body = "The main body text of you mail" attachment1 = "Path to attachment no. 1" attachment2 = "Path to attachment no. 2" Msg.Attachments.Add(attachment1) Msg.Attachments.Add(attachment2) Msg.Send()
I wrote code like this
and the error:
Traceback (most recent call last):
File “C:/Users/satz/PycharmProjects/PYWork/Sample/EmailSample1.py”, line 33, in
send_notification()
File “C:/Users/satz/PycharmProjects/PYWork/Sample/EmailSample1.py”, line 12, in send_notification
mail.To = ‘abc@abc.com’,
File “C:\Users\satz\PycharmProjects\PYWork\venv\lib\site-packages\win32com\client\dynamic.py”, line 565, in __setattr__
self._oleobj_.Invoke(entry.dispid, 0, invoke_type, 0, value)
pywintypes.com_error: (-2147352567, ‘Exception occurred.’, (4096, u’Microsoft Outlook’, u’The object does not support this method.’, None, 0, -2147352567), None)
Hi,
What if i want to change “from” of email?
Do you know something like
mail. from=”abc@..com” or mail.sender. None of them works for me.
mail.SentOnBehalfOfName = ‘whatever@abc.com’
You have to remove the comma at the end of ‘mailTo’-line. This is leading to the error you get.
Hi,
My company using outlook mailer I want to sent mail for my corporate mail id (xys@company.com) using python.
Please help me.
Hi Venkat,
Any one responded to this query, i need answer to update in my script. please help me
Hi I am not able to send email multiple recipient . Can you advise how to fix it?
com_error: (-2147352567, ‘Exception occurred.’, (4096, ‘Microsoft Outlook’, ‘Cannot add the attachment; no data source was provided.’, None, 0, -2147352567), None)
I get this error message even though the path to the attachment is correct.
Use this
How to protect same email ? please help
I am trying to read mail using pywin32 but but m not able to fetch all inbox item
Hey, what if i need to send the email to more than one accounts at the same time (not using a FOR loop to send it)
Thank you so much, Edson
It works for me!
Use this
Great stuff, how to set confidentiality label (Azure information protection), like confidential, internal, restricted etc.? Thanks.
mail.Sensitivity = 1
mail.Confidentiality = “Internal”
mail.Label = 1
I tried all the 3, nothing seem to work
hi, any help on setting the confidentiality label (Azure information protection) values?
I am also kinda stuck on this step.
how to add more recipients in cc?
Hey there,
you can simply use this:
Msg.CC = ‘Amy; john; sandy’
Best regards
Michael
Hi,
how to send multiple email in same thread in outlook
A Help, how to limit the size of files in the Attachments.Add?