Change/Set maximum message size for Python smtplib

Viewed 4999

I have written a Python script which zips a folder and attaches it to an email and sends the email to the recipients.

But the zipped folder size is around 1.6 MB and hence I get the below error.

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

Is there a way to change/remove the max limit or some other work around for my problem?

1 Answers

You need to increase size limit of your send-mail server and receive-mail server, but that is not recommended because it may overload your mail server. First check your mail size

import smtplib    
smtp = smtplib.SMTP('server.name')    
smtp.ehlo()    
max_limit_in_bytes = int( smtp.esmtp_features['size'] )

Then change size limit on your mail servers:

postconf -e "message_size_limit = 26214400"
Related