Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

3,564 views
Skip to first unread message

bruceg...@gmail.com

unread,
Jul 23, 2012, 1:19:40 PM7/23/12
to
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("som...@email.com") #enter valid email here

appt.Save()
appt.Send()

print "Done"


Ian Kelly

unread,
Jul 23, 2012, 2:11:05 PM7/23/12
to Python
On Mon, Jul 23, 2012 at 11:19 AM, <bruceg...@gmail.com> wrote:
> 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.

bruceg...@gmail.com

unread,
Jul 23, 2012, 2:33:02 PM7/23/12
to
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

pyt...@bdurham.com

unread,
Jul 23, 2012, 4:20:17 PM7/23/12
to bruceg...@gmail.com, pytho...@python.org
> Problem is, this line is not understood:
>
> mail.BodyFormat = OlBodyFormat.olFormatHTML

Try olBodyFormat (lower case 'o')

Malcolm

Ian Kelly

unread,
Jul 23, 2012, 4:32:36 PM7/23/12
to Python
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

Emile van Sebille

unread,
Jul 23, 2012, 5:02:23 PM7/23/12
to pytho...@python.org
On 7/23/2012 11:33 AM bruceg...@gmail.com 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

bruceg...@gmail.com

unread,
Jul 23, 2012, 5:24:02 PM7/23/12
to comp.lan...@googlegroups.com, Python
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

bruceg...@gmail.com

unread,
Jul 23, 2012, 5:24:02 PM7/23/12
to Python

bruceg...@gmail.com

unread,
Jul 23, 2012, 8:42:15 PM7/23/12
to Python

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




bruceg...@gmail.com

unread,
Jul 23, 2012, 8:42:15 PM7/23/12
to comp.lan...@googlegroups.com, Python

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"
0 new messages