提问人:bartu celasun 提问时间:9/27/2023 更新时间:9/27/2023 访问量:28
Outlook 显示“这是一封 HTML 电子邮件”。
Outlook displays "This is an HTML email."
问:
当我通过python发送电子邮件时。Outlook 显示“这是一封 HTML 电子邮件”。Gmail 运行良好。
这是正文:
使用排序的 URL 创建电子邮件正文
body = "<html><body><div style='background-color: #0072c6; padding: 10px;'>"
body += "<h2 style='color: #fff; margin: 0;'>Latest News:</h2>"
body += "</div><ul style='list-style-type: none; padding: 0;'>"
for url_info in matching_urls:
summary, title, date, name, keywords, url = url_info
body += f"<li style='margin-bottom: 10px;'><strong><a href=\"{url}\" style='color:
body += f"<span style='font-size: 14px;'><strong>Date:</strong> {date}</span><br>"
body += f"<span style='font-size: 14px;'><strong>Summary:</strong> {summary}</span><br>"
body += f"<span style='font-size: 14px;'><strong>Keywords:</strong>
body += "</ul></body></html>"
em = EmailMessage()
em["From"] = sender_email
em["To"] = ", ".join(reciever_emails) # Combine recipient emails with commas
em["Subject"] = subject
em.set_content("This is an HTML email.", subtype="html")
em.add_alternative(body, subtype="html")
file_path = "/tmp/News.xlsx"
# Attach the Excel file to the email
with open(file_path, "rb") as excel_file:
em.add_attachment(
excel_file.read(),
maintype="application",
subtype="vnd.openxmlformats-officedocument.spreadsheetml.sheet",
filename="News.xlsx"
)
context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as smtp:
smtp.login(sender_email, password)
smtp.sendmail(sender_email, reciever_emails, em.as_string())`
答: 暂无答案
评论
set_content
text/plain