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

Discussion in 'Python' started by bruceg113355@gmail.com, Jul 23, 2012.

  1. Guest

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

    appt.Save()
    appt.Send()

    print "Done"
     
    , Jul 23, 2012
    #1
    1. Advertising

  2. Ian Kelly Guest

    On Mon, Jul 23, 2012 at 11:19 AM, <> 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.
     
    Ian Kelly, Jul 23, 2012
    #2
    1. Advertising

  3. Guest

    , Jul 23, 2012
    #3
  4. Guest

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


    Try olBodyFormat (lower case 'o')

    Malcolm
     
    , Jul 23, 2012
    #4
  5. Ian Kelly Guest

    On Mon, Jul 23, 2012 at 12:33 PM, <> 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
     
    Ian Kelly, Jul 23, 2012
    #5
  6. On 7/23/2012 11:33 AM 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
    >
     
    Emile van Sebille, Jul 23, 2012
    #6
  7. Guest

    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
     
    , Jul 23, 2012
    #7
  8. Guest

    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
     
    , Jul 23, 2012
    #8
  9. Guest

    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
     
    , Jul 24, 2012
    #9
  10. Guest

    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
     
    , Jul 24, 2012
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    569
    AdamM
    Jul 27, 2004
  2. Fabio Negri Cicotti [MCP]

    Image displayed on email's body

    Fabio Negri Cicotti [MCP], Nov 25, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    9,230
    Peter Kron
    Dec 1, 2004
  3. John Kotuby
    Replies:
    2
    Views:
    1,639
    John Kotuby
    Jan 28, 2008
  4. London Boy
    Replies:
    2
    Views:
    356
    Keith Bowes
    Jan 12, 2004
  5. heycooldude
    Replies:
    0
    Views:
    278
    heycooldude
    Mar 26, 2014
Loading...

Share This Page