Hello, I’ve using Realm to send AWS SES emails for 3 years now, from everything from user auth to newsletters. Starting on April 13th 2023 (or a few days before) all emails have garbled characters appearing everywhere, many strange characters appearing instead of accented characters, but sometimes the garbled text appears on spaces and common characters too!
I’ve spent quite a lot of time debugging and narrowed it down at “possibly” the context.http.get method changed somehow, and now has problems with utf8 charset.
I’d like to reassure that the error appeared without any changes on the Realm dependencies and no changes at all on our server. The only coincidence is that you upgraded the Atlas Shared clusters to MongoDB 6.0.5.
I will share some screenshots to illustrate the using, and also a working code below.
Before:
After:
from this HTML email: The world in you - typo/graphic posters
Before (error on spaces):
After (error before spaces):
Before: (error before spaces):
After: (error before spaces):
I’m using AWS SDK v3 as dependency, but tried with v2 just now and the error is the same.
Tried with @aws-sdk/client-sesv2 3.261.0, 3.267.0, 3.67.0, neither work.
Tried with aws-sdk 2.1360.0, too.
**What could be the cause? Realm Functions downgraded somehow? **
Is there a charset issue on context.http now?
Thanks!
Here the code:
exports = async function() {
const from = 'FROM_EMAIL'
const to = 'TO_EMAIL'
// get email HTML
const emailHtml = await context.http.get({
url: 'https://www.typographicposters.com/newsletters/the-world-in-you'
})
const body = emailHtml.body.text()
// send email
const { SESv2Client, SendEmailCommand } = require('@aws-sdk/client-sesv2')
const client = new SESv2Client({
region: 'us-east-1',
credentials: {
accessKeyId: context.values.get('AwsSesKey'),
secretAccessKey: context.values.get('AwsSesSecret'),
},
})
const command = new SendEmailCommand({
FromEmailAddress: from,
Destination: {
ToAddresses: [to],
},
Content: {
Simple: {
Subject: {
Data: 'Test from Realm',
Charset: 'UTF-8',
},
Body: {
Html: {
Data: body,
Charset: 'UTF-8', // tried with ISO-8859-1, the garbled characters just change
},
},
},
},
})
await client.send(command)
// for AWS SDK v2 here is the code
// const Ses = require("aws-sdk/clients/ses");
// const client = new Ses({
// region: 'us-east-1',
// credentials: {
// accessKeyId: context.values.get('AwsSesKey'),
// secretAccessKey: context.values.get('AwsSesSecret'),
// },
// })
// const params = {
// Source: from,
// Destination: { ToAddresses: [to] },
// Message: {
// Body: {
// Html: {
// Charset: "UTF-8",
// Data: body
// }
// },
// Subject: {
// Charset: 'UTF-8',
// Data: 'Test from Realm with AWS SDK v2'
// }
// }
// }
// await client.sendEmail(params).promise();
};