首页 > 解决方案 > 使用python的邮件中的图像?

问题描述

我编写了一个脚本来发送包含 html 格式图像的邮件,但不幸的是,当我发送邮件时,我发现了如下图

请指教?

目的地收到时的图像

脚本:

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import os


#Credentials data
host="smtp.gmail.com"
port=587
from_email="engminazarief@gmail.com"
to_email="mina.zarif@outlook.com"
password="yallakora@2018"
subject="Hello World"

try:
#Mail connection
email_conn=smtplib.SMTP(host,port)
email_conn.ehlo()
email_conn.starttls()
email_conn.login(from_email,password)

#Mail data
msg=MIMEMultipart("alternative")
msg['Subject']=subject
msg['From']=from_email
msg['To']=to_email
## HTML
html_body= """\
<body>
<p style="text-indent: 4em;">
<img src="~path~\page5.jpg">
</p>

</body>
"""
body=MIMEText(html_body,"html")
msg.attach(body)

#Send mail
email_conn.sendmail(from_email,to_email,msg.as_string())
email_conn.quit()
except smtplib.SMTPException:
"error sending mail"

标签: pythonemailsmtplib

解决方案


推荐阅读