AWS SES-Nodemailer-transporter.sendEmail不是函数

时间:2018-09-14 09:31:48

标签: amazon-web-services aws-lambda amazon-ses nodemailer

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。

1 个答案:

答案 0 :(得分:0)

应该为transporter.sendMail

http://nodemailer.com/usage/#sending-mail