Embed PDF on shared drive into an HTML email

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

Answers:

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.

Method 1

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x