Discussion:
Python and Outlook, sendinf an image in the body of email
(too old to reply)
b***@gmail.com
2012-07-23 17:19:40 UTC
Permalink
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("***@email.com") #enter valid email here

appt.Save()
appt.Send()

print "Done"
Ian Kelly
2012-07-23 18:11:05 UTC
Permalink
Post by b***@gmail.com
All,
I am trying to figure out how to send a image in the body of a email when Making a Meeting Request.
You need to use html in the body with an <img> tag that references the
attachment. See:

http://stackoverflow.com/questions/4312687/how-to-embed-images-in-email

One of the answers there contains an Outlook-specific example, which
is written in C# but should still be translatable to what you are
doing.
b***@gmail.com
2012-07-23 18:33:02 UTC
Permalink
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

Bruce
p***@bdurham.com
2012-07-23 20:20:17 UTC
Permalink
Post by b***@gmail.com
mail.BodyFormat = OlBodyFormat.olFormatHTML
Try olBodyFormat (lower case 'o')

Malcolm
Ian Kelly
2012-07-23 20:32:36 UTC
Permalink
Post by b***@gmail.com
I tried something similar to the example at http://stackoverflow.com/questions/4312687/how-to-embed-images-in-email .
mail.BodyFormat = OlBodyFormat.olFormatHTML
...
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
b***@gmail.com
2012-07-23 21:24:02 UTC
Permalink
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***@gmail.com
2012-07-23 21:24:02 UTC
Permalink
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***@gmail.com
2012-07-24 00:42:15 UTC
Permalink
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***@gmail.com
2012-07-24 00:42:15 UTC
Permalink
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

Emile van Sebille
2012-07-23 21:02:23 UTC
Permalink
Post by b***@gmail.com
I tried something similar to the example at http://stackoverflow.com/questions/4312687/how-to-embed-images-in-email .
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
Post by b***@gmail.com
...
appt.BodyFormat = OlBodyFormat.olFormatHTML
NameError: name 'OlBodyFormat' is not defined
Bruce
Loading...