图像附件发送?但在电子邮件消息Python smtp中并不适用

时间:2017-06-01 22:21:02

标签: python smtp attachment

我正在尝试发送屏幕截图以及电子邮件..

消息很好。

在Windows Live邮件中,它有附件图标。但没有附件。

在线上看它没有依恋..

msg = MIMEMultipart('alternative')
msg['Subject'] = client_name + "  eBay Template " + date
msg['From'] = sender_address
msg['To'] = recipients_address
msg.preamble = 'images'

...     #attach screenshot

iways_filename = dictstr['ItemID'] + "_i-ways" + '.png'
ebay_filename = dictstr['ItemID'] + "_ebay" + '.png'
# iways
img_data = open(iways_filename, 'rb').read()
image = MIMEImage(img_data, name=os.path.basename(iways_filename))
msg.attach(image)
#ebay
img_data2 = open(ebay_filename, 'rb').read()
image = MIMEImage(img_data2, name=os.path.basename(ebay_filename))
msg.attach(image)   

我没有错误..

1 个答案:

答案 0 :(得分:0)

我找到了解决方案..

msg = MIMEMultipart('alternative')
msg['Subject'] = client_name + "  eBay Template " + date
msg['From'] = sender_address
msg['To'] = recipients_address
msg.preamble = 'images'

带走“替代品”#39;和Voila!

msg = MIMEMultipart()
msg['Subject'] = client_name + "  eBay Template " + date
msg['From'] = sender_address
msg['To'] = recipients_address
msg.preamble = 'images'