如何在使用python发送电子邮件时在正文中插入图像

2024-09-27 00:22:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我可以在msg区域插入图像,可以作为附件或html代码。 我尝试过使用html代码,但它只是将html代码作为字符串输出

import pandas as pd
import smtplib

SenderAddress='<xxxx@gmail.com>'

e = pd.read_excel("C:-=-.Email.xls")
emails = e['Emails'].values
server = smtplib.SMTP("smtp.gmail.com:587")
server.starttls()
server.login('xxx@gmail.com', 'xxxxx')

msg = 'image here'

subject = "Test"
body = "Subject: {}\n\n{}".format(subject,msg.as_string())
for email in emails:
  server.sendmail(SenderAddress, email, body)
server.quit()

Tags: 代码importcomserveremailhtmlasbody

热门问题