Home > database >  Add signature at Outlook using Python win32
Add signature at Outlook using Python win32

Time:03-09

I'am trying to create a code where I can send automatic emails. This code works fine but I need my signature to be add at the email body as well.

At first I thought that using mail.Display(), outlook would add the signature but it doesn't, I haven't tried to use GetInspector because i read that it isn't working anymore

An idea I had was to add a printscreen from the signature, I used mail.display() to see the email before send it, the printscreen was there. I sent it to myself and the printscreen was an empty figure/image with an X

Then, I tried this, to add the outlook signature htm archive at the code but, well, hasn't worked either

import win32com.client

outlook = win32com.client.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = '[email protected]'
mail.CC = '[email protected];[email protected]'
mail.Subject = 'Teste - 2'
mail.HTMLBody = '<p>Hi<p>' \
                '<p>Thats the code :))<p>' \
                '<p> <figure><img src=c://Users/AppData/Roaming/Microsoft/Signaturesa/Teste.Htm </figure>'
Attachments=("c://Users/lucas/Downloads/USIM5.xlsx")
mail.Attachments.Add(Attachments)
mail.display()
mail.Send()

CodePudding user response:

You need to attach an image to the mail item:

import win32com.client

outlook = win32com.client.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = '[email protected]'
mail.CC = '[email protected];[email protected]'
mail.Subject = 'Teste - 2'
Attachments=("c://Users/lucas/Downloads/USIM5.xlsx")

mail.Attachments.Add(Attachments)

pathToIMage = `c://Users/AppData/Roaming/Microsoft/Signaturesa/Teste.png`
attachment = mail.Attachments.Add(pathToIMage)

attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "MyId1")

mail.HTMLBody = '<p>Hi<p>' \
                '<p>Thats the code :))<p>' \
                '<p> <figure><img src=""cid:MyId1""</figure>'
mail.display()
mail.Send()

CodePudding user response:

Remote recipients do not have access to a local image file stored on your computer. To add an embedded image to an email, see https://stackoverflow.com/a/17197140/332059

  • Related