Here is my python code to convert my .png image to base64 encoding:
import base64
email_img = base64.b64encode(open('rmh.png', 'rb').read()).decode('utf-8').replace('\n','')
img_tag = '<img alt="" src="data:image/png;base64,{}"/>'.format(email_img)
This code is running without error and is properly storing the base64 encoding in the email_img variable. However, I have been unable to display the image in an outlook email. Here is an abbreviated version of my code relevant to the image:
import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = email[0]
mail.Subject = "UTAS Job Matches"
mail.HtmlBody = """\
<html>
<head></head>
<body>
<p>{}<br>
</p>
</body>
</html>
""".format(img_tag)
mail.Display(True)
I have tried both .format and the %s method for inserting the variables and neither work. The resulting email shows a box with a red X where the image should be. I have not had any trouble with the text I am displaying in my email.