Sep-09-2018, 02:48 PM
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.
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 conceptThanks in advance!