My python script is creating a PDF that is stored on a shared T: drive. I want to take this PDF and embed it into the body of an HTML email script using the file path. I have sent HTML emails before with images embedded but they have always come from an online source.
Like “src = https:// www . somewebsite.com/image.jpg”
Is there a way to embed this PDF using just the file path?
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Did a workaround. Made my PDFs into jpegs and then did this:
data = open(rf'path.jpg', 'rb').read() # read bytes from file data_base64 = base64.b64encode(data) # encode to base64 (bytes) data_base64 = data_base64.decode() # convert bytes to string code = '<img src="data:image/jpeg;base64,' + data_base64 + '">' # embed in html open('output.html', 'w').write(code) #add html to a text file to be read by email