使用 smtplib 和 email.message.EmailMessage 发送电子邮件时未显示徽标/图像

问题描述

我正在尝试发送包含 HTML 模板的电子邮件。一切都很好,但徽标/图像没有出现。这里有什么问题,我该怎么办?

这里是python代码:-

from flask import request,url_for,render_template
from flask_login import current_user
from ifileshifts import EMAIL_ADDRESS,EMAIL_PASSWORD
from ifileshifts.models import Connection
from email.message import EmailMessage
import smtplib

#fun: Send email.
def send_email(subject,to_email,secret,size,emails,file_count,recipient_type):
    sender_msg = EmailMessage()
    sender_msg['Subject'] = subject
    sender_msg['From'] = EMAIL_ADDRESS
    sender_msg['To'] = to_email
    link = url_for('main.download_link_page',secret=secret,_external=True)
    if recipient_type == 'sender':
        sender_msg.add_alternative(render_template('others/send_email.html',domain=request.url_root,emails=emails,link=link,file_count=file_count,size=size),subtype='html')
    else:
        connection_id = Connection.query.filter_by(sender=current_user,receiver_email=to_email).first().id
        open_ifileshifts = url_for('dashboard.messenging',id=connection_id,_external=True)
        sender_msg.add_alternative(render_template('others/receive_email.html',sender_email=emails,size=size,open_ifileshifts=open_ifileshifts,subject=subject),subtype='html')
    with smtplib.SMTP_SSL('a2plcpnl0820.prod.iad2.secureserver.net',465) as smtp:
        smtp.login(EMAIL_ADDRESS,EMAIL_PASSWORD)
        smtp.send_message(sender_msg)

这是图像div:-

<div class="logo-center" align="center" id="emb-email-header">
    <img style="display: block;height: auto;width: 100%;border: 0;max-width: 50px;" src="{{domain}}static/img/logo.png" alt="" width="50">
</div>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)