Parthiva
Parthiva

Reputation: 290

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;
    }
};

I have the following code which gives a error saying 'transporter.Email' is not a function. I have the following dependencies specified in my package.json (Some content is stripped but it is a valid 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"
    }
}

At the first look, it does not look like a permissions issue, so ruling that out. Any pointers to fix it would be of great help.

I am using Node.js 8.10 in lambda.

Upvotes: 2

Views: 4385

Answers (1)

givehug
givehug

Reputation: 2001

Should be transporter.sendMail

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

Upvotes: 2

Related Questions