Categories About Us Contact Us Become a Member

How to fix “E12505 Invalid attachment content” for .eml attachments

This is raised by email sending APIs when an attached .eml file is not encoded the way the API expects. The payload usually needs to be a complete base64 string, and the API rejects it when that encoding is missing or broken. Jump to your situation below or work through the methods in order.

By Neeraj Singh ~7 min Updated Jun 2026 90% found this helpful
Error message
E12505: Invalid attachment content. The attachment stream could not be processed.
Summary

Error E12505 is returned by email sending APIs such as Kaleyra or SendGrid when the content of an attached .eml file cannot be processed. These APIs expect the attachment payload as a properly base64-encoded string, along with a filename and a content type, and they reject the request when the encoding is missing, truncated or malformed. The usual mistakes are sending the raw .eml bytes instead of an encoded string, producing a partial or corrupted base64 value, reading the file as text so bytes are altered, or exceeding the API's attachment size limit. The fix is to read the .eml as binary, base64-encode the whole file, and send it in the fields the API expects with the content type set to message/rfc822. Verifying the encoded value by decoding it back confirms it is complete before you send.

What this error means

Email APIs do not accept raw binary inside a JSON or form request, so attachments are carried as text. The convention is base64: the file's bytes are encoded into an ASCII string, sent, then decoded by the API. E12505 means that decoding step failed because the content was not valid base64.

So the problem is in how the attachment was prepared, not in the .eml file itself in most cases. Sending the raw bytes, a truncated string, or a value mangled by reading the file as text all produce an attachment stream the API cannot turn back into a file, and it responds with E12505.

Common causes

The .eml content was not base64-encoded before sending.
The base64 string is truncated or missing padding.
The file was read as text, which altered bytes before encoding.
Line breaks or whitespace corrupted the base64 value.
The raw binary was sent where the API expects an encoded string.
The attachment exceeds the API's size limit.
The content was encoded with the wrong character set.
Expert insight

“E12505 is almost always an encoding bug, not a bad file. The .eml is fine, it is the way it was handed to the API that is wrong. The classic mistake is reading the file as text in whatever language you are using, which quietly rewrites bytes, then base64-encoding the damaged result. I tell people to do two things: read the file in binary mode, and after encoding, decode it back and check the byte count matches the original. If those two line up, E12505 goes away.”

How to fix it

Method 1

Base64-encode the whole .eml file

1Read the .eml and encode its full contents to base64, then send that string as the attachment content.
2Do not send the raw file bytes or a file path, the API wants the encoded string.
3Encode the entire file, not just part of it.
Method 2

Read the file as binary

1Open and read the .eml in binary mode so no bytes are changed before encoding.
2Reading as text can rewrite line endings or characters and corrupt the base64.
3This single change fixes many E12505 cases.
Method 3

Send the fields the API expects

1Provide the attachment as the API documents it, typically content (the base64 string), filename (for example message.eml), and type.
2Set the type to message/rfc822 for an .eml.
3Do not leave the content or type fields blank.
Method 4

Verify the base64 is complete

1After encoding, decode the string back and confirm the result matches the original file size byte for byte.
2Check the base64 has correct padding and no stray line breaks or spaces.
3A complete, valid string is what the API needs to rebuild the file.
Method 5

Stay under the size limit

1Check the API's maximum attachment size and keep the .eml under it.
2Base64 inflates size by about a third, so account for that against the limit.
3Split or compress where a single attachment is too large.
Method 6

Test with a small known-good file

1Send a tiny, valid .eml to confirm your encoding and fields are correct.
2Once that succeeds, the problem is isolated to the original file or its size.
3Scale back up from there.

E12505 is an encoding problem, so reach for your code, not the .eml file. Reading the file in binary mode and base64-encoding the whole thing fixes the large majority of cases. Always verify by decoding the string back to the exact original size before sending, that single check catches truncation and corruption every time.

Frequently asked questions

What does E12505 mean?
It means an email API such as Kaleyra or SendGrid could not process the content of an attached .eml. The attachment payload was not valid base64, so the API could not rebuild the file.
How do I base64-encode an .eml correctly?
Read the file in binary mode and encode its full contents to a base64 string. Send that string as the attachment content, not the raw bytes or a file path.
Why does reading the file as text break it?
Text mode can rewrite line endings and characters, which changes the bytes and corrupts the base64. Always read attachments in binary mode.
How do I check the base64 is valid?
Decode the string back to bytes and confirm the size matches the original file exactly. Also confirm the padding is correct and there are no stray spaces or line breaks.
Could the size cause E12505?
Yes. If the encoded attachment exceeds the API limit it can be rejected. Base64 adds about a third to the size, so keep the original well under the documented limit.
What content type should an .eml attachment use?
Use message/rfc822, which is the MIME type for an email message file. Set it in the type field alongside the base64 content and the filename.

Still not working?

If the encoding is verified and the .eml still returns E12505, test the exact same file through the API's web console or a minimal sample request to rule out your client code. If the console accepts it, the bug is in how your code builds the request body. You can also submit your error to us for a tailored fix.

Was this fix helpful? Thanks for your feedback!