日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

python含多个附件的邮件_Python发送带有多个图像附件的电子邮件

發布時間:2023/12/1 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python含多个附件的邮件_Python发送带有多个图像附件的电子邮件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我試圖用Python發送一封帶有多個圖像附件的電子郵件。但是通過下面的代碼,我可以在正文中包含第一個圖像,但是第二個圖像會作為附件附加到電子郵件中。有沒有辦法可以在HTML的主體中同時獲得這兩個圖像?下面是我當前的代碼。在from email.mime.multipart import MIMEMultipart

from email.mime.text import MIMEText

from email.mime.image import MIMEImage

strFrom = 'user@provider.com'

strTo = 'user@provider.com'

msgRoot = MIMEMultipart('related')

msgRoot['Subject'] = 'Test message'

msgRoot['From'] = 'user@provider.com'

msgRoot['To'] = 'user@provider.com'

msgRoot.preamble = 'This is a multi-part message in MIME format.'

msgAlternative = MIMEMultipart('alternative')

msgRoot.attach(msgAlternative)

msgText = MIMEText('This is the alternative plain text message.')

msgAlternative.attach(msgText)

msgText = MIMEText('Test HTML with Images
'

''

'
'

'
'

''

'
'

'
'

'Sending Two Attachments', 'html')

msgAlternative.attach(msgText)

fp = open('image1.png', 'rb')

msgImage = MIMEImage(fp.read())

fp.close()

msgImage.add_header('Content-ID', '')

msgRoot.attach(msgImage)

fp = open('image2.png', 'rb')

msgImage2 = MIMEImage(fp.read())

fp.close()

msgImage.add_header('Content-ID', '')

msgRoot.attach(msgImage2)

import smtplib

smtp = smtplib.SMTP('localhost')

smtp.sendmail(strFrom, strTo, msgRoot.as_string())

smtp.quit()

總結

以上是生活随笔為你收集整理的python含多个附件的邮件_Python发送带有多个图像附件的电子邮件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。