AWS SES - Nodemailer - transporter.sendEmail 不是函数
AWS SES - Nodemailer - transporter.sendEmail is not a function
const nodemailer = require('nodemailer');
const aws = require('aws-sdk');
aws.config.update({ region: 'myRegion');
const senderEmail = process.env.SENDER_EMAIL;
const destinationEmail = process.env.DESTINATION_EMAIL;
const transporter = nodemailer.createTransport({
SES: new aws.SES({
apiVersion: '2010-12-01'
})
});
exports.handler = async (event) => {
let request = event.body;
try {
await this.sendEmail(request);
return {
'statusCode': 201,
'headers': {
'Access-Control-Allow-Origin': '*'
}
};
} catch (error) {
return {
'statusCode': 500
};
}
};
exports.sendEmail = async (request) => {
try {
await transporter.sendEmail({
from: senderEmail,
to: destinationEmail,
subject: 'Hello',
text: 'Hello using SES'
});
} catch (error) {
console.log(error);
throw error;
}
};
我有下面的代码,它给出了一个错误,说 'transporter.Email' 不是一个函数。我在我的 package.json 中指定了以下依赖项(一些内容被删除但它是有效的 JSON)
{
"devDependencies": {
"aws-sdk": "^2.267.1",
"chai": "^4.1.2",
"eslint": "^5.1.0",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-standard": "^3.1.0",
"hippie-swagger": "^3.2.0",
"mocha": "^5.1.1",
"mochawesome": "^3.0.3",
"sinon": "^6.1.0",
"swagger-parser": "^5.0.2"
},
"dependencies": {
"axios": "^0.18.0",
"nodemailer": "^4.6.8",
"nodemailer-ses-transport": "^1.5.1"
}
}
乍一看,这不像是权限问题,所以排除了。任何修复它的指示都会有很大帮助。
我在 lambda 中使用 Node.js 8.10。
应该是transporter.sendMail
const nodemailer = require('nodemailer');
const aws = require('aws-sdk');
aws.config.update({ region: 'myRegion');
const senderEmail = process.env.SENDER_EMAIL;
const destinationEmail = process.env.DESTINATION_EMAIL;
const transporter = nodemailer.createTransport({
SES: new aws.SES({
apiVersion: '2010-12-01'
})
});
exports.handler = async (event) => {
let request = event.body;
try {
await this.sendEmail(request);
return {
'statusCode': 201,
'headers': {
'Access-Control-Allow-Origin': '*'
}
};
} catch (error) {
return {
'statusCode': 500
};
}
};
exports.sendEmail = async (request) => {
try {
await transporter.sendEmail({
from: senderEmail,
to: destinationEmail,
subject: 'Hello',
text: 'Hello using SES'
});
} catch (error) {
console.log(error);
throw error;
}
};
我有下面的代码,它给出了一个错误,说 'transporter.Email' 不是一个函数。我在我的 package.json 中指定了以下依赖项(一些内容被删除但它是有效的 JSON)
{
"devDependencies": {
"aws-sdk": "^2.267.1",
"chai": "^4.1.2",
"eslint": "^5.1.0",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-standard": "^3.1.0",
"hippie-swagger": "^3.2.0",
"mocha": "^5.1.1",
"mochawesome": "^3.0.3",
"sinon": "^6.1.0",
"swagger-parser": "^5.0.2"
},
"dependencies": {
"axios": "^0.18.0",
"nodemailer": "^4.6.8",
"nodemailer-ses-transport": "^1.5.1"
}
}
乍一看,这不像是权限问题,所以排除了。任何修复它的指示都会有很大帮助。
我在 lambda 中使用 Node.js 8.10。
应该是transporter.sendMail