日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

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

發布時間:2023/12/1 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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发送带有多个图像附件的电子邮件的全部內容,希望文章能夠幫你解決所遇到的問題。

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