I’m trying to send a raw e-mail using AWS SES, with the AWS SDK v3 for Node.JS.
However, the e-mail I’m sending is appearing on the receiving end with the raw body enclosed in a HTML container, including the headers. So instead of headers being parsed as headers, they are simply ending up as part of the body.
As far as I can see, I’m including all the headers mandatory as per the E-mail RFC, I’m separating headers and body with an empty lines, etc. But still, the entire raw message ends up being interpreted as a plaintext body, not a MIME raw message.
const msg = `
From: "No-Reply" <[email protected]>
To: [email protected]
Date: Wed, 4 Sep 2024 19:02:29 +0000
Subject: Test
Content-Type: text/plain
MIME-Version: 1.0
Hello, world!
`;
const ses = new SES({region: 'eu-west-1'});
const result = await ses.sendRawEmail({
Destinations: ["[email protected]"],
RawMessage: {
Data: Buffer.from(msg)
},
Source: 'No-Reply <[email protected]>'
});
This e-mail is received with the entire msg
string in the body, and no subject, to or date fields since the headers are not recognized as headers.
What am I missing?
The AWS SDK accepts a RawMessage.Data
in the form of UInt8Array
, so passing a Buffer
should work. The documentation says the content does not have to be base64 encoded as the SDK handles that (supposedly that’s why you pass a Buffer instead of a string). My point being that I don’t think the string encoding is the issue?
Ok, seems the initial newline was the culprit here, meaning this solved the problem:
const msg = `From: "No-Reply" <[email protected]>
To: [email protected]
Date: Wed, 4 Sep 2024 19:02:29 +0000
Subject: Test
Content-Type: text/plain
MIME-Version: 1.0
Hello, world!
`