Python Forum
Python win32com add image in HTML body of email
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python win32com add image in HTML body of email
#1
At the moment i am building an automatic email send system through Outlook in Python 3.x.

One of the requirements is to add a signature with an image. I have some working code, please see below but i am not sure if this is the correct way to do it.

At the moment i am adding an image as attachment to the email and use it in the HTML body.

attachment = mail.Attachments.Add(signatureimage)
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "MyId1")
body = "<h1>Test body with image</h1><br><br>" + (windowsname) + "<br><br> <img src=""cid:MyId1"" height=""42"" width=""42"">"
Should i keep using this method or is it better to switch to base64 or insert the image from a webserver??

windowsname = get_display_name()
userprofilepath = (os.environ['USERPROFILE'])
signatureimage = (userprofilepath) + "\\AppData\\Roaming\\Microsoft\\Signatures\\Tst_bestanden\\image001.png"

outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
attachment = mail.Attachments.Add(signatureimage)
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "MyId1")
body = "<h1>Test body with image</h1><br><br>" + (windowsname) + "<br><br> <img src=""cid:MyId1"" height=""42"" width=""42"">"
mail.To = '[email protected]'
mail.Subject = 'Message subject'
mail.HTMLBody = (body)
mail.Save()#save as concept
Thanks in advance!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Save image from outlook email cubangt 1 649 Jun-07-2023, 06:52 PM
Last Post: cubangt
  Looking to automate updating a spreadsheet with image from email cubangt 2 944 Feb-14-2023, 03:43 PM
Last Post: cubangt
  Tkinterweb (Browser Module) Appending/Adding Additional HTML to a HTML Table Row AaronCatolico1 0 877 Dec-25-2022, 06:28 PM
Last Post: AaronCatolico1
  is it possible to copy image from email and place into excel file? cubangt 3 1,212 Nov-30-2022, 05:11 PM
Last Post: snippsat
  Upload image to Instagram using python/selenium using image URL failed, need help greenpine 5 5,341 Feb-22-2022, 09:42 PM
Last Post: snippsat
  win32com — How to resolve “AttributeError: xlUp” for Excel files? JaneTan 2 4,129 Aug-18-2021, 05:27 AM
Last Post: snippsat
Exclamation win32com: How to pass a reference object into a COM server class Alfalfa 3 4,802 Jul-26-2021, 06:25 PM
Last Post: Alfalfa
  reading html and edit chekcbox to html jacklee26 5 3,023 Jul-01-2021, 10:31 AM
Last Post: snippsat
  How can I get Python Bulk Email Verification Script With API? zainalee 1 2,461 Jun-06-2021, 09:19 AM
Last Post: snippsat
  Python with win32com and EXIF renaming files. Amrcodes 4 3,596 Apr-03-2021, 08:51 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020