1
votes

I'm using Mailgun for sending emails. The mail has a short subject (11 characters), a text body which its maximum line length 115 characters and a PDF attached. I'm getting some errors from Mailgun (on very few emails) with message: "550 Maximum line length exceeded (see RFC 5322 2.1.1)." RFC 5322, 2.1.1 says that the maximum line length is 998 characters excluding the CRLF.

As my email's longest line is way shorter than that, is it possible that this issue is being caused by a header, CSS rule or the attachment?

4

4 Answers

4
votes

The attachment should not be a problem. If you have css, then I suspect you have html body as well. I would check out the line lengths there and in the text body. Maybe a line break is missing somewhere.

1
votes

I ran into the same error and I wanted to make a more definite answer: CSS is counted in the line length limit, so if you have a lot of CSS with no line breaks, it will cause this error.

0
votes

The server will only allow so many (550 or 980) characters per line. When there are no line breaks, all the HTML is counted as a single line.

So the simple solution is to add a few line breaks in the email body. That is put a few \r\n in the body of the message.

0
votes

I ran into this problem when an attachment I had included in my raw email (encoded in base64) was longer than 998 characters. As the error suggests, this is due to RFC5322 section 2.1.1.

I resolved it by chunking the base64 up into lines of 1000 characters each (which is 998 + \r\n). PHP has a function for this called chunk_split, and a similar thing can be done in JavaScript with a regex implementation of chunk_split