我已经编写了一个Python脚本,它会发送一封带有附件的电子邮件,但我总是收到相同的错误消息:

raise SMTPSenderRefused(code, resp, from_addr)
smtplib.SMTPSenderRefused: (552, b'5.3.4 Message size exceeds fixed maximum mess
age size', '[email protected]')

如何更改服务器上的最大邮件大小限制以避免此错误消息并正确发送附件?
我用代码更新了我的问题:
emailfrom = "myemailadress"
    emailto = "1.person"
    emailto = "2.person"
    fileToSend = "data.csv"
    username = "user"
    password = "password"

msg = MIMEMultipart()
msg["From"] = emailfrom
msg["To"] = emailto
msg["Subject"] = "subject"
msg.preamble = "subject"

ctype, encoding = mimetypes.guess_type(fileToSend)
if ctype is None or encoding is not None:
    ctype = "application/octet-stream"

maintype, subtype = ctype.split("/", 1)

if maintype == "text":
    fp = open("data.csv")
    # Note: we should handle calculating the charset
    attachment = MIMEText(fp.read(), _subtype=subtype)
    fp.close()
elif maintype == "image":
    fp = open("data.csv", "rb")
    attachment = MIMEImage(fp.read(), _subtype=subtype)
    fp.close()
elif maintype == "audio":
    fp = open("data.csv", "rb")
    attachment = MIMEAudio(fp.read(), _subtype=subtype)
    fp.close()
else:
    fp = open("data.csv", "rb")
    attachment = MIMEBase(maintype, subtype)
    attachment.set_payload(fp.read())
    fp.close()
    encoders.encode_base64(attachment)
attachment.add_header("Content-Disposition", "attachment", filename="data.csv")
msg.attach(attachment)

#server = smtplib.SMTP("smtp.gmail.com:587")
server = smtplib.SMTP('smtp.upcmail.hu', 25)
#server.starttls()
#server.login(username,password)
server.sendmail(emailfrom, emailto, msg.as_string())
server.quit()

time.sleep(5)

我不知道如何更改服务器上的最大消息大小限制,我使用的是Debian。

最佳答案

这看起来像来自postfix的错误消息。
你可以用

postconf message_size_limit

并增加它
postconf -e 'message_size_limit = 104857600'

即100 MB。之后你必须重新加载配置
service postfix reload

请记住,Postfix在发送附件之前会转换附件,因此大小限制必须稍大一些。

09-06 01:15