【发布时间】:2019-11-26 10:38:22
【问题描述】:
我们每天使用 Python 脚本生成电子邮件并向业务用户发送每日报告。 在这些电子邮件中,我们添加了报告的 PrintScreen。在这种情况下,用户无需在手机上打开附件(PDF),就可以在电子邮件中看到结果(报告的编号)。
但问题是,对于某些 iPhone 机型,图像非常模糊,无法看到图像的内容。
安卓手机没问题。
对于 iPhone 有没有办法说像 请不要把图片的质量缩小这么多。
添加图片的函数:
def send_email(send_to, subject, html, plain, img_path, cc):
try:
# prepare date for email subject
scorecard_date = date.today() - timedelta(1)
# prepare message
msg = MIMEMultipart()
msg['From'] = email_user
msg['To'] = send_to
msg['Subject'] = subject + ' - for ' + scorecard_date.strftime('%d/%m/%Y')
# attach cc if applicable
if cc is not None:
msg['Cc'] = cc
send_to = [send_to, cc]
# attach plain or html body
if html is not None:
msg.attach(MIMEText(html, 'html'))
else:
msg.attach(MIMEText(plain, 'plain'))
# attach image if applicable
if img_path is not None:
fp = open(img_path, 'rb')
msg_image = MIMEImage(fp.read())
msg_image.add_header('Content-ID', '<image1>')
msg.attach(msg_image)
fp.close()
# create server instance and send email
server = smtplib.SMTP(smtp_host, smtp_port)
server.starttls()
server.login(email_user, sc.get_email_pass())
text = msg.as_string()
server.sendmail(email_user, send_to, text)
server.quit()
# return ok
return 0
except:
# something went wrong - probably timeout
return 1
在电子邮件正文中插入图像的 HTML 标记:
<div style="line-height:15px;font-size:1px"> </div> <img class="left autowidth fullwidth" align="left" border="0" src="cid:image1" alt="Image" title="Image" style="outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;clear: both;display: block !important;border: 0;height: auto;float: none;width: 150%;max-width: 1024px" width="1024">
谢谢你, 大流士
【问题讨论】:
标签: html css iphone html-email