我正在使用aiosmtpd附带的默认SMTP服务器,并且我已经将size变量修改为833554432(很大)
我正在使用默认的smtplib.SMTP库实际发送电子邮件。
我仍然无法通过它发送大文件。它的大小似乎在1.5mb左右。我没有在日志中发现任何错误,它只是从不发送quit命令,因此服务器也永远不会发送电子邮件
#assume files = ['file_to_attach', 'another_file']
from smtplib import SMTP
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
import os.path
msg = MIMEMultipart()
msg.attach(MIMEText(body))
for path in files:
part = MIMEBase('application', "octet-stream")
with open(path, 'rb') as file:
part.set_payload(file.read())
encoders.encode_base64(part)
part.add_header('Content-Disposition',
'attachment; filename="{}"'.format(os.path.basename(path)))
msg.attach(part)
s = SMTP(host, port)
s.send_message(msg)