Python and Outlook, sendinf an image in the body of email

B

bruceg113355

All,

I am trying to figure out how to send a image in the body of a email when Making a Meeting Request.
Below is my current code.

Thanks,
Bruce


# code below is mainly from http://harunprasad.blogspot.com/2012/01/python-make-meeting-request-appointment.html
# --------------------------------------------------------------------------------------------------------------

import win32com.client
oOutlook = win32com.client.Dispatch("Outlook.Application")
appt = oOutlook.CreateItem(1)
appt.Start = '2012-07-24 08:00'
appt.Subject = '5th Meeting'
appt.Duration = 60
appt.Location = 'Conference Room, Main'


appt.Body = "This is body text\n"
attach1 = "someimage.jpg"
appt.Attachments.Add (attach1) #prefer to have attachment inline (body) of email

appt.MeetingStatus = 1

appt.Recipients.Add("(e-mail address removed)") #enter valid email here

appt.Save()
appt.Send()

print "Done"
 
I

Ian Kelly

I tried something similar to the example at http://stackoverflow.com/questions/4312687/how-to-embed-images-in-email .

Problem is, this line is not understood:
mail.BodyFormat = OlBodyFormat.olFormatHTML

Traceback (most recent call last):
...
appt.BodyFormat = OlBodyFormat.olFormatHTML
NameError: name 'OlBodyFormat' is not defined

Assuming you've run makepy to generate the static dispatch Python module for the
Outlook type library, all generated constants are available via
win32com.client.constants Try:

appt.BodyFormat = win32com.client.constants.olFormatHTML
 
E

Emile van Sebille

On 7/23/2012 11:33 AM (e-mail address removed) said...
I tried something similar to the example at http://stackoverflow.com/questions/4312687/how-to-embed-images-in-email .

Problem is, this line is not understood:
mail.BodyFormat = OlBodyFormat.olFormatHTML

If I read the example properly, this is bvisual basic and should result
in some form of visual basic error (possibly library related) if
anything and not a python traceback.

Emile
 
B

bruceg113355

These do not work:

appt.BodyFormat = olBodyFormat.olFormatHTML
...
appt.BodyFormat = olBodyFormat.olFormatHTML
NameError: name 'olBodyFormat' is not defined



appt.BodyFormat = win32com.client.constants.olFormatHTML
...
appt.BodyFormat = win32com.client.constants.olFormatHTML
File "C:\Python26\lib\site-packages\win32com\client\__init__.py",
line 170, in __getattr__
raise AttributeError(a)
AttributeError: olFormatHTML


Bruce
 
B

bruceg113355

These do not work:

appt.BodyFormat = olBodyFormat.olFormatHTML
...
appt.BodyFormat = olBodyFormat.olFormatHTML
NameError: name 'olBodyFormat' is not defined



appt.BodyFormat = win32com.client.constants.olFormatHTML
...
appt.BodyFormat = win32com.client.constants.olFormatHTML
File "C:\Python26\lib\site-packages\win32com\client\__init__.py",
line 170, in __getattr__
raise AttributeError(a)
AttributeError: olFormatHTML


Bruce
 
B

bruceg113355

This assignment works:
import win32com.client
oOutlook = win32com.client.Dispatch("Outlook.Application")
appt = oOutlook.CreateItem(0)
appt.BodyFormat = win32com.client.constants.olFormatHTML

But this assignment does not work:
import win32com.client
oOutlook = win32com.client.Dispatch("Outlook.Application"
appt = oOutlook.CreateItem(1) #appointment
appt.BodyFormat = win32com.client.constants.olFormatHTML

AttributeError: ... object has no attribute 'BodyFormat'

It simply appears an Appointment Item does not support .BodyFormat
Images are delivered as attachments, can not be in the body (inline) of the appointment email.


Bruce
 
B

bruceg113355

This assignment works:
import win32com.client
oOutlook = win32com.client.Dispatch("Outlook.Application")
appt = oOutlook.CreateItem(0)
appt.BodyFormat = win32com.client.constants.olFormatHTML

But this assignment does not work:
import win32com.client
oOutlook = win32com.client.Dispatch("Outlook.Application"
appt = oOutlook.CreateItem(1) #appointment
appt.BodyFormat = win32com.client.constants.olFormatHTML

AttributeError: ... object has no attribute 'BodyFormat'

It simply appears an Appointment Item does not support .BodyFormat
Images are delivered as attachments, can not be in the body (inline) of the appointment email.


Bruce
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top