Send an outlook email using python with out SMTP

PHOTO EMBED

Fri Mar 05 2021 05:36:48 GMT+0000 (UTC)

Saved by @SurendraReddy ##python ##outlook

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 = "testemail@company.com"
attachment1 = r"C:\Temp\example.pdf"
newMail.Attachments.Add(Source=attachment1)
newMail.display(True)
newMail.Send()
content_copyCOPY

Windows machine

https://gist.github.com/ITSecMedia/b45d21224c4ea16bf4a72e2a03f741af