Skip to content

Instantly share code, notes, and snippets.

@6220119
Forked from ITSecMedia/outlook_email.py
Created February 8, 2018 03:02
Show Gist options
  • Save 6220119/8c3983ece7b63df23aae1a818f805b91 to your computer and use it in GitHub Desktop.
Save 6220119/8c3983ece7b63df23aae1a818f805b91 to your computer and use it in GitHub Desktop.
Python: Create an Email with Outlook
# http://itsecmedia.com/blog/post/2016/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@demo.com"
attachment1 = r"C:\Temp\example.pdf"
newMail.Attachments.Add(Source=attachment1)
newMail.display()
newMail.send()
@JBSilvaDev
Copy link

JBSilvaDev commented Nov 22, 2021

Hi, can you help with this error

OBS: I'm Braziliam

Screenshot_1

@DeividBertapele
Copy link

Hey good afternoon!

Could use a correct information would be to use this path here:

==> email.Attachments.Add(str(attachment)) (you have to use Strings because of the parameter).

Oi, você pode ajudar com este erro

OBS: Sou brasileiro

Captura de tela_1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment