2023-08-06 18:27:36 +02:00
|
|
|
import { SESv2Client, SendEmailCommand } from '@aws-sdk/client-sesv2'
|
|
|
|
|
|
|
|
export const send = async ({
|
|
|
|
to = ['joost@joost.at'],
|
|
|
|
bcc = [],
|
|
|
|
subject = false,
|
|
|
|
html = false,
|
|
|
|
text = false,
|
|
|
|
}) => {
|
|
|
|
if (!subject || !html || !text) return console.log('No subject, html, or text provided')
|
|
|
|
|
|
|
|
const us = 'Joost from FreeSewing <info@freesewing.org>'
|
|
|
|
|
|
|
|
// Oh AWS your APIs are such a clusterfuck
|
|
|
|
const client = new SESv2Client({ region: 'us-east-1' })
|
|
|
|
|
|
|
|
// Via API
|
|
|
|
const command = new SendEmailCommand({
|
|
|
|
ConfigurationSetName: 'backend',
|
|
|
|
Content: {
|
|
|
|
Simple: {
|
|
|
|
Body: {
|
|
|
|
Text: {
|
|
|
|
Charset: 'utf-8',
|
|
|
|
Data: text,
|
|
|
|
},
|
|
|
|
Html: {
|
|
|
|
Charset: 'utf-8',
|
|
|
|
Data: html,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Subject: {
|
|
|
|
Charset: 'utf-8',
|
|
|
|
Data: subject,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Destination: {
|
|
|
|
ToAddresses: to,
|
2023-08-08 11:31:16 +02:00
|
|
|
BccAddresses: bcc,
|
2023-08-06 18:27:36 +02:00
|
|
|
},
|
|
|
|
FromEmailAddress: us,
|
|
|
|
})
|
|
|
|
try {
|
|
|
|
const result = await client.send(command)
|
|
|
|
console.log(result)
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|