我使用了一个env文件,我使用了这样的结构,并得到了如何解决该错误的信息
"AWS_SES_REGION":"us-east-1" and i have put us-west-2 also but still getting the same error
"AWS_ACCESS_KEY_ID":"value"
"AWS_SECRET_KEY":"value"
这是我用来发送电子邮件的代码,任何人都可以建议我如何解决此问题
require('dotenv').config();
const AWS = require('aws-sdk');
const SESConfig = {
apiVersion:"2010-12-01",
accessKeyId:process.env.AWS_SECRET_KEY,
accessSecretKey:process.env.AWS_SECRET_KEY,
region:process.env.AWS_SES_REGION
}
// AWS.SESConfig.update({region: 'eu-central-1'});
var params = {
Source: '[email protected]',
Destination: {
ToAddresses: [
'[email protected]'
]
},
ReplyToAddresses: [
'[email protected]',
],
Message: {
Body: {
Html: {
Charset: "UTF-8",
Data: 'IT IS <strong>WORKING</strong>!'
}
},
Subject: {
Charset: 'UTF-8',
Data: 'Node + SES Example'
}
}
};
new AWS.SES(SESConfig).sendEmail(params).promise().then((res) => {
console.log(res);
}).catch(error => {
console.log(error)
});
尝试使用AWS.Config
类加载配置。
示例:
require('dotenv').config();
const AWS = require('aws-sdk');
const SESConfig = {
apiVersion: "2010-12-01",
accessKeyId: process.env.AWS_SECRET_KEY,
accessSecretKey: process.env.AWS_SECRET_KEY,
region: process.env.AWS_SES_REGION
}
AWS.config(SESConfig); // Load the configuration like this.
var params = {
Source: '[email protected]',
Destination: {
ToAddresses: [
'[email protected]'
]
},
ReplyToAddresses: [
'[email protected]',
],
Message: {
Body: {
Html: {
Charset: "UTF-8",
Data: 'IT IS <strong>WORKING</strong>!'
}
},
Subject: {
Charset: 'UTF-8',
Data: 'Node + SES Example'
}
}
};
new AWS.SES().sendEmail(params).promise().then((res) => {
console.log(res);
}).catch(error => {
console.log(error)
});