I'm trying to add an image to an HTML body of an email, and I am not getting an error in the code, rather the following message is where the image should be: "The linked image cannot be displayed. The file may have been moved, renamed, or deleted. Verify that the link points to the correct file and location." However, the path of the image is correct (I've tripled checked).
Here's my code:
Imports
import win32com.client as win32
from datetime import datetime
import base64
from pathlib import Path
from PIL import Image
Code
Header = Path.home().joinpath("Desktop", "EmailPictures", "header.png")
Header = str(Header)
with open(Header, 'rb') as image_file:
image_data = image_file.read()
# Encode the image data as base64
image_base64 = base64.b64decode(image_data).decode('latin-1')
And here's a snippet of my HTML code:
<table id="nw_mastheadimage_wrapper" class="nw_component_wrapper" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<table cellpadding="0" cellspacing="0" class="ContentBlock" id="mastheadimage" style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;" width="100%">
<tbody>
<tr>
<img src="data:image/png;base64,{image_base64}" alt="Embedded Image" width="650" height="150">
</tr>
</tbody>
</table>
</tr>
</tbody>
</table>
Any help would be greatly appreciated.
Thanks in advance.