-
-
Save ITSecMedia/b45d21224c4ea16bf4a72e2a03f741af to your computer and use it in GitHub Desktop.
# https://itsec.media/post/python-send-outlook-email/ | |
import win32com.client | |
from win32com.client import Dispatch, constants | |
const=win32com.client.constants | |
olMailItem = 0x0 | |
obj = win32com.client.Dispatch("Outlook.Application") | |
newMail = obj.CreateItem(olMailItem) | |
newMail.Subject = "I AM SUBJECT!!" | |
# newMail.Body = "I AM\nTHE BODY MESSAGE!" | |
newMail.BodyFormat = 2 # olFormatHTML https://msdn.microsoft.com/en-us/library/office/aa219371(v=office.11).aspx | |
newMail.HTMLBody = "<HTML><BODY>Enter the <span style='color:red'>message</span> text here.</BODY></HTML>" | |
newMail.To = "[email protected]" | |
attachment1 = r"C:\Temp\example.pdf" | |
newMail.Attachments.Add(Source=attachment1) | |
newMail.display() | |
newMail.Send() |
I want to create a email and save it in draft.. How to do it ? Any help would be highly appreciated and Thank you in Advance!
Hi Norman, first I want to thank you for publishing this snippet. Please do you know, if there is any change to select a sender account from outlook? I have 5 inboxes in my outlook and the email is sent from the 3rd account.
Thanks.
@Stehos, I would expect that you define the default sender account in your Email client, try to look there for a solution.
Hello,
Please help/guide me to achieve below goal. Any help is truly appreciated and I remember for my life time 😊.
What I want to do?
- I have outlook template file (.oft).
- I have Some values in excel.
- Insert values of excel into outlook template using python.
Thanks in advance
I want to create a email and save it in draft.. How to do it ? Any help would be highly appreciated and Thank you in Advance!
You can use newMail.Save()
.
Hi,
Thanks for this post! It´s really usefull.
Do you know the propertie or the command to change the "from" mailbox?
Thanks in advance!
Hi,
Thanks for this post! It´s really usefull.
Do you know the propertie or the command to change the "from" mailbox?Thanks in advance!
Try it with the Sender properties, check the link below
newMail.Sender = "...."
newMail.SenderEmailAddress= "...."
newMail.SenderName = "...."
https://docs.microsoft.com/en-us/office/vba/api/outlook.mailitem
Hi, thanks for the post!
Do you know if it's any chance to bring the mail signature of my mail?
Thank you again!
Hello, i want to ask how i can set a random sender and how i can set random Timestamp?
With the Faker module like this:
newMail.Sender= fake_data.email()
newMail.Timestamp=fake_data.iso8601()
It doesnt work yet. Has someone an idea?
Hello, just tried Email.Sender & Email.SenderEmailAddress & Email.SenderName, also tried Email.SendUsingAccount , but none of them works.
Any idea? Thanks.
Thanks.. it works for me,
How to import existing mail signature into the new mail