基本使用
import AWS from 'aws-sdk';
const ses = new AWS.SES({ region: process.env.region });
const SES = {
async send (source: string, recipients: string[], subject: string, body: string) {
const params = {
Destination: {
ToAddresses: recipients
},
Message: {
Body: {
Text: { Data: body },
},
Subject: { Data: subject },
},
Source: source,
};
try {
console.log('Sending email...');
await ses.sendEmail(params).promise();
console.log('done.');
} catch (error) {
console.log(error);
}
}
};
export default SES;
注意事项
在sandbox中,无论是发送方,还是接收方的邮件地址,都需要事先通过验证才能使用。
在产品模式中,可以发送给未经过验证的邮件,但需要在AWS控制台中先进行申请。