Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

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

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


bruceg113355 at gmail

Jul 23, 2012, 10:19 AM

Post #1 of 10 (1630 views)
Permalink
Python and Outlook, sendinf an image in the body of email

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("someone [at] email") #enter valid email here

appt.Save()
appt.Send()

print "Done"


--
http://mail.python.org/mailman/listinfo/python-list


ian.g.kelly at gmail

Jul 23, 2012, 11:11 AM

Post #2 of 10 (1577 views)
Permalink
Re: Python and Outlook, sendinf an image in the body of email [In reply to]

On Mon, Jul 23, 2012 at 11:19 AM, <bruceg113355 [at] gmail> 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.
--
http://mail.python.org/mailman/listinfo/python-list


bruceg113355 at gmail

Jul 23, 2012, 11:33 AM

Post #3 of 10 (1578 views)
Permalink
Re: Python and Outlook, sendinf an image in the body of email [In reply 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
--
http://mail.python.org/mailman/listinfo/python-list


python at bdurham

Jul 23, 2012, 1:20 PM

Post #4 of 10 (1573 views)
Permalink
Re: Python and Outlook, sendinf an image in the body of email [In reply to]

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

Try olBodyFormat (lower case 'o')

Malcolm
--
http://mail.python.org/mailman/listinfo/python-list


ian.g.kelly at gmail

Jul 23, 2012, 1:32 PM

Post #5 of 10 (1589 views)
Permalink
Re: Python and Outlook, sendinf an image in the body of email [In reply to]

On Mon, Jul 23, 2012 at 12:33 PM, <bruceg113355 [at] gmail> wrote:
> 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
--
http://mail.python.org/mailman/listinfo/python-list


emile at fenx

Jul 23, 2012, 2:02 PM

Post #6 of 10 (1581 views)
Permalink
Re: Python and Outlook, sendinf an image in the body of email [In reply to]

On 7/23/2012 11:33 AM bruceg113355 [at] gmail 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

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



--
http://mail.python.org/mailman/listinfo/python-list


bruceg113355 at gmail

Jul 23, 2012, 2:24 PM

Post #7 of 10 (1571 views)
Permalink
Re: Python and Outlook, sendinf an image in the body of email [In reply to]

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
--
http://mail.python.org/mailman/listinfo/python-list


bruceg113355 at gmail

Jul 23, 2012, 2:24 PM

Post #8 of 10 (1580 views)
Permalink
Re: Python and Outlook, sendinf an image in the body of email [In reply to]

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
--
http://mail.python.org/mailman/listinfo/python-list


bruceg113355 at gmail

Jul 23, 2012, 5:42 PM

Post #9 of 10 (1586 views)
Permalink
Re: Python and Outlook, sendinf an image in the body of email [In reply to]

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




--
http://mail.python.org/mailman/listinfo/python-list


bruceg113355 at gmail

Jul 23, 2012, 5:42 PM

Post #10 of 10 (1574 views)
Permalink
Re: Python and Outlook, sendinf an image in the body of email [In reply to]

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




--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.