使用此类我正在尝试将gif url加载到multipart/mixed
中。
问题是,对于某些网址,加载需要10秒,其他2秒。
我几乎尝试过任何东西,但过程太慢了。 1秒钟会很好,但我从未成功过去。
我也尝试过UIWebview,它有自己的问题。
以下是代码:
from smtplib import SMTP
from email.message import EmailMessage
from email.mime.text import MIMEText
from email.headerregistry import Address
from ssl import SSLContext, PROTOCOL_TLSv1_2
# Creating and populating email data:
msg = EmailMessage()
msg['From'] = Address(display_name='Recipient', addr_spec='rcpt@example.org')
msg['To'] = Address(display_name='Sender', addr_spec='sender@example.org')
msg['Subject'] = 'An email for you'
msg.set_content('This should be in the email body')
# It is possible to use msg.add_alternative() to add HTML content too
# Attaching content:
att = MIMEText('This should be in an attached file') # Or use MIMEImage, etc
# The following line is to control the filename of the attached file
att.add_header('Content-Disposition', 'attachment', filename='attachment.txt')
msg.make_mixed() # This converts the message to multipart/mixed
msg.attach(att) # Don't forget to convert the message to multipart first!
# Sending the email:
with SMTP(host='smtp.example.org', port=587) as smtp_server:
try:
# You can choose SSL/TLS encryption protocol to use as shown
# or just call starttls() without parameters
smtp_server.starttls(context=SSLContext(PROTOCOL_TLSv1_2))
smtp_server.login(user='user@smtp.example.org', password='password')
smtp_server.send_message(msg)
except Exception as e:
print('Error sending email. Details: {} - {}'.format(e.__class__, e))
答案 0 :(得分:1)
我看过的大多数GIF阅读工具的问题是它们在加载时读取所有数据,并且它们为所有已解码的帧分配内存并同时在内存中保存所有未压缩的数据。这将导致运行时性能问题,它会使您的应用程序和可能的设备崩溃在大/长GIF上。关于加载时间的问题,由于需要下载和读取数据,因此您无法做很多事情。您也只是假设网络缓存将一次又一次地处理相同的GIF,而无需再次访问网络,这可能适用于您,也可能不适合您。有关解决这些问题的解决方案,请参阅this SO Question,或者您也可以查看flipboard解决方案here。