New guide: how to warm up a dedicated IP without hurting your reputation. Read now →
Log in
MigoSMTP
TroubleshootingUpdated 26 Oct 2026

Email Line Length Limits: The 998 and 78 Character Rules, Long URLs and Broken HTML

Why email lines must stay under 998 characters (and should stay near 78), what breaks when they do not, how soft wrapping and quoted-printable work, long URLs, minified HTML and how to fix and test your templates.

KM
Written by Kwame Mensah
Billing and Account Specialist
Reviewed by Kenji Watanabe
  • Published14 Feb 2025
  • Read time7 min
  • Length1,338 words
Share this guide

Some email problems have nothing to do with reputation or content: the message simply contains a line that is too long. Compact HTML produced by a build tool, a long tracking URL or a base64 blob with no line breaks can make a message violate the format rules of email, and the result is a bounce with a cryptic "line too long" message, a template that breaks in the middle of an attribute or a body that arrives with strange extra spaces. These rules are old, but they remain in force because email passes through many independent systems. This guide explains the limits, the reasons, what happens in each system when they are exceeded and how to fix them in templates and code. It complements Base64 overhead, MIME encoded-words and CSS support in email.

Hard limit998 characters per line, excluding the CR LF line ending (RFC 5322)
RecommendedKeep lines to 78 characters or fewer
FixUse a MIME library that wraps lines, or use quoted-printable with soft breaks for HTML
TestScan the raw message for lines over 998 characters before sending

The rules

RuleSourceMeaning
Lines MUST NOT exceed 998 charactersRFC 5322 (message format)Absolute maximum, not counting the CR LF
Lines SHOULD NOT exceed 78 charactersRFC 5322Recommended for readability and compatibility
SMTP command lines up to 512 characters, text lines up to 1000 including CR LFRFC 5321The SMTP transport limit for lines in the DATA section is 1000 characters including the line ending
Encoded lines in Base64 and quoted-printable at most 76 charactersRFC 2045 (MIME)Encoders wrap their output at 76
Encoded-words at most 75 charactersRFC 2047Headers with non-ASCII text are split. See encoded-words
Header lines are folded by inserting CR LF before whitespaceRFC 5322A folded header counts as one logical line

Line endings in email are CR LF (carriage return, line feed). Bare LF or bare CR characters inside a message are not allowed by the standard, and some servers fix them silently while others reject the message. Because DKIM signs the message as transmitted, a server that rewrites line endings can invalidate your signature. See DKIM signed headers.

Why the limit exists

Many mail programs and gateways read a message line by line into fixed-size buffers. A line of unbounded length would require unbounded buffers, and old software dealt with the problem by wrapping or truncating lines. The 998 character limit gives every implementation a safe maximum, and 78 characters fits the width of a classic terminal. Modern software is more flexible, but the weakest system on the path sets the practical limit, and security gateways use line length as one of several anomaly signals.

What happens when a line is too long

SystemTypical behaviour
Sending MTAMay reject the message ("500 line too long") or wrap the line by inserting a break, sometimes in the wrong place
Relay or gatewayRewraps lines, inserts a space or newline, or refuses the message
Receiving serverRejects with 500 5.5.2 or 552; some accept and silently wrap at 998 characters
Mail clientDisplays the wrapped result; HTML may break inside a tag, an attribute or a URL
DKIM verifierFails the body hash if any system changed the bytes after signing
Spam filterMay add points for abnormal line lengths or malformed HTML

The most frequent visible symptom is an HTML email whose layout breaks randomly or contains a stray space in a link or style value. A forced wrap in the middle of style="color:#ff0000" or in a long URL breaks it, and the recipient sees a broken layout or a link that does not work.

Where long lines come from

  • Minified HTML. Build tools and template compilers often output the entire document on one line. A 40 KB email in one line breaks the limit forty times over.
  • Long tracking URLs. Redirect links with encoded parameters can exceed several hundred characters. Several of them on one line add up quickly.
  • Inline data. Embedded images as data: URIs produce enormous attribute values. Host images externally instead. See image hosting.
  • Custom code building messages by string concatenation. Without a library, the body is written as sent by the application, with whatever line lengths it has.
  • Plain-text parts made from HTML with all spaces and breaks removed. See plain-text email.
  • Raw JSON or logs pasted into a message, as in alerts and notification emails.

Fixes

  1. Use a proper MIME library and choose a transfer encoding for text parts. Quoted-printable inserts soft line breaks (an equals sign at the end of a line) that decoders remove, so the original long line is restored exactly on display. Base64 wraps at 76 characters automatically.
  2. For HTML you construct yourself, insert harmless line breaks at safe points: between tags, after a closing tag, between attributes. Most build tools have an option to keep a line width limit or to format output.
  3. Avoid breaks inside attribute values and URLs. Wrap before an attribute or after a tag, never within the quotes.
  4. Shorten URLs by using short paths on your own tracking domain and fewer parameters. See link reputation for why to avoid public shorteners.
  5. Keep the plain-text part tidy, with lines near 70 characters and URLs on their own lines.
  6. Set line endings to CR LF in raw construction code; let the library handle normalisation.
  7. Sign after the final encoding so that DKIM covers the bytes that will be transmitted.
# Find lines over 998 characters in a saved raw message (message.eml)
awk '{ if (length($0) > 999) print NR": "length($0) }' message.eml

# Check for bare LF line endings (should print nothing for CRLF files)
grep -c -v $'\r$' message.eml

# Python: build a message with automatic encoding choices
from email.message import EmailMessage
m = EmailMessage()
m.set_content(text_body)
m.add_alternative(html_body, subtype="html")   # library selects quoted-printable or base64
print(max(len(l) for l in m.as_bytes().splitlines()))

Quoted-printable in brief

In quoted-printable, printable ASCII characters stand for themselves, other bytes are written as an equals sign and two hexadecimal digits (for example =C3=A9 for the letter é in UTF-8), and a line ending with an equals sign means "soft break, join with the next line". A literal equals sign is written =3D, which is why raw HTML source in a message often shows style=3D"...". Recipients never see this because the client decodes it. When debugging, decode the part first, then examine the HTML. If you see =3D in the rendered message, the decoding step is missing or applied twice.

Frameworks and email builders

If you use a templating engine or a visual email builder, check how it outputs HTML before blaming the relay. Some builders emit one very long line by default, while others offer an option such as "pretty print", "preserve whitespace" or "wrap at N characters". Inline-CSS tools that move styles into attributes can create very long style values; keep rule sets short and avoid repeating the same declarations everywhere. In server-side code, send HTML as a separate alternative part rather than mixing it with text, and let the library apply the transfer encoding to each part separately. When you add a footer or tracking snippet through a gateway, remember that the gateway sees the message after your application, so verify the final output at the recipient end rather than in your preview.

Testing

  1. Send the final message to a test mailbox and export the raw source.
  2. Measure the longest line in each part (headers, text, HTML). Anything above 998 characters is a defect; above 78 is acceptable only for encoded or URL-heavy content.
  3. View the message in several clients and look for stray spaces, broken links and misaligned layout.
  4. Check the DKIM result in the Authentication-Results header. See authentication results.
  5. Test through the same relay and gateways used in production, since they may rewrap lines.
  6. Add the line-length check to your template release routine. See the pre-send checklist.

Line length is a small technical detail that quietly breaks a surprising number of emails. Let a library choose encodings, format generated HTML with sensible breaks, keep URLs short and measure the raw message before it goes out, and the problem disappears.

Send through a standards-aware relay Consistent encoding and signing after all changes.

Explore SMTP relay

References and further reading

Frequently asked questions

What is the maximum line length in an email?

998 characters excluding the CR LF, with 78 characters recommended.

Why does my HTML email break in the middle of a link?

A long line was wrapped by a system on the way, possibly inside a tag or URL; format the HTML with safe breaks.

What does quoted-printable do about long lines?

It adds soft line breaks with a trailing equals sign that decoders remove, restoring the original long line.

Can long lines break DKIM?

Yes. If any system rewraps lines after signing, the body hash no longer matches.

How can I check line lengths?

Export the raw message and measure the longest line with a script such as awk or Python.

Topics#line length#html#mime#quoted-printable#templates
Was this guide helpful?Your answer helps us improve our documentation.

Start sending in minutes.

Create an account, add your domain and send your first email.

Get started Talk to sales