I am trying to send an email with an attachment as the body of the email. I want to replicate the attach-->insert as text option that you can use in the actual Outlook application.
This is the code I have tried, but it does not work to insert my document as text in the body of the email.
import win32com.client
#some constants (from http://msdn.microsoft.com/en-us/library/office/aa219371%28v=office.11%29.aspx)
olFormatHTML = 2
olFormatPlain = 1
olFormatRichText = 3
olFormatUnspecified = 0
olMailItem = 0x0
obj = win32com.client.Dispatch("Outlook.Application")
attachment1 = "test.docx"
with open(attachment1 , 'r') as myfile:
data=(myfile.read())
newMail = obj.CreateItem(olMailItem)
newMail.Subject = "I AM SUBJECT!!"
newMail.BodyFormat = olFormatHTML #or olFormatRichText or olFormatPlain
newMail.HTMLBody = data
newMail.HTMLBody = "<h1>I am a title</h1><p>I am a paragraph</p>"
newMail.To = "help@example.com"
newMail.Attachments.Add(Source=attachment1)
# open up in a new window and allow review before send
newMail.Display()