我的 python 腳本正在創建一個存盤在共享 T: 驅動器上的 PDF。我想獲取此 PDF 并使用檔案路徑將其嵌入到 HTML 電子郵件腳本的正文中。我以前發送過嵌入影像的 HTML 電子郵件,但它們總是來自在線資源。
像“src = https://www.somewebsite.com/image.jpg”
有沒有辦法只使用檔案路徑來嵌入這個 PDF?
謝謝
uj5u.com熱心網友回復:
做了一個解決方法。將我的 PDF 轉換為 jpeg,然后執行以下操作:
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/351196.html
