Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #25907 > unrolled thread

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

Started bybruceg113355@gmail.com
First post2012-07-23 10:19 -0700
Last post2012-07-23 14:02 -0700
Articles 10 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  Python and Outlook, sendinf an image in the body of email bruceg113355@gmail.com - 2012-07-23 10:19 -0700
    Re: Python and Outlook, sendinf an image in the body of email Ian Kelly <ian.g.kelly@gmail.com> - 2012-07-23 12:11 -0600
    Re: Python and Outlook, sendinf an image in the body of email bruceg113355@gmail.com - 2012-07-23 11:33 -0700
      Re: Python and Outlook, sendinf an image in the body of email python@bdurham.com - 2012-07-23 16:20 -0400
      Re: Python and Outlook, sendinf an image in the body of email Ian Kelly <ian.g.kelly@gmail.com> - 2012-07-23 14:32 -0600
        Re: Python and Outlook, sendinf an image in the body of email bruceg113355@gmail.com - 2012-07-23 14:24 -0700
        Re: Python and Outlook, sendinf an image in the body of email bruceg113355@gmail.com - 2012-07-23 14:24 -0700
          Re: Python and Outlook, sendinf an image in the body of email bruceg113355@gmail.com - 2012-07-23 17:42 -0700
          Re: Python and Outlook, sendinf an image in the body of email bruceg113355@gmail.com - 2012-07-23 17:42 -0700
      Re: Python and Outlook, sendinf an image in the body of email Emile van Sebille <emile@fenx.com> - 2012-07-23 14:02 -0700

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

Frombruceg113355@gmail.com
Date2012-07-23 10:19 -0700
SubjectPython and Outlook, sendinf an image in the body of email
Message-ID<641dab69-9782-4bf3-8a01-34237c4f189a@googlegroups.com>
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@email.com") #enter valid email here

appt.Save()
appt.Send()

print "Done"

[toc] | [next] | [standalone]


#25910

FromIan Kelly <ian.g.kelly@gmail.com>
Date2012-07-23 12:11 -0600
Message-ID<mailman.2490.1343067097.4697.python-list@python.org>
In reply to#25907
On Mon, Jul 23, 2012 at 11:19 AM,  <bruceg113355@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.

[toc] | [prev] | [next] | [standalone]


#25914

Frombruceg113355@gmail.com
Date2012-07-23 11:33 -0700
Message-ID<22e9b14a-d660-4ec9-a67b-0fcdc9ef1463@googlegroups.com>
In reply to#25907
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

[toc] | [prev] | [next] | [standalone]


#25918

Frompython@bdurham.com
Date2012-07-23 16:20 -0400
Message-ID<mailman.2495.1343074825.4697.python-list@python.org>
In reply to#25914
> Problem is, this line is not understood:
> 
> mail.BodyFormat = OlBodyFormat.olFormatHTML

Try olBodyFormat (lower case 'o')

Malcolm

[toc] | [prev] | [next] | [standalone]


#25919

FromIan Kelly <ian.g.kelly@gmail.com>
Date2012-07-23 14:32 -0600
Message-ID<mailman.2496.1343075588.4697.python-list@python.org>
In reply to#25914
On Mon, Jul 23, 2012 at 12:33 PM,  <bruceg113355@gmail.com> 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

[toc] | [prev] | [next] | [standalone]


#25925

Frombruceg113355@gmail.com
Date2012-07-23 14:24 -0700
Message-ID<mailman.2502.1343078651.4697.python-list@python.org>
In reply to#25919
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

[toc] | [prev] | [next] | [standalone]


#25926

Frombruceg113355@gmail.com
Date2012-07-23 14:24 -0700
Message-ID<69adceee-49d0-4348-b439-04b6362ebd0d@googlegroups.com>
In reply to#25919
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

[toc] | [prev] | [next] | [standalone]


#25939

Frombruceg113355@gmail.com
Date2012-07-23 17:42 -0700
Message-ID<354a3a37-3ce9-4992-a017-e4f5d8feeb55@googlegroups.com>
In reply to#25926
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



[toc] | [prev] | [next] | [standalone]


#25940

Frombruceg113355@gmail.com
Date2012-07-23 17:42 -0700
Message-ID<mailman.2512.1343090538.4697.python-list@python.org>
In reply to#25926
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



[toc] | [prev] | [next] | [standalone]


#25921

FromEmile van Sebille <emile@fenx.com>
Date2012-07-23 14:02 -0700
Message-ID<mailman.2498.1343077226.4697.python-list@python.org>
In reply to#25914
On 7/23/2012 11:33 AM bruceg113355@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

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


[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web