如何更改服务器上的最大邮件大小限制?

时间:2017-11-13 07:23:20

标签: python email smtp email-attachments smtpclient

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

raise SMTPSenderRefused(code, resp, from_addr)
smtplib.SMTPSenderRefused: (552, b'5.3.4 Message size exceeds fixed maximum mess
age size', 'notification@company.com')

如何更改服务器上的最大邮件大小限制以避免出现此错误消息并正确发送带有附件的电子邮件?

我用我的代码更新了我的问题:

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。

1 个答案:

答案 0 :(得分:0)

这看起来像是来自后缀的错误消息。

您可以使用

检查尺寸限制
postconf message_size_limit

并增加

postconf -e 'message_size_limit = 104857600'

至100 MB。之后,您必须重新加载配置

service postfix reload

请记住,Postfix在发送附件之前会先对其进行转换,因此大小限制必须稍大。