Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodemailer and Amazon SES

My structure:

site
-- node_modules
---- nodemailer
-- webclient
---- js
------- controller.js

site/node_modules/nodemailer
site/webclient/js/controller.js

site/webclient/js/controller.js:

    var nodemailer = require('../../node_modules/nodemailer');

    var transport = nodemailer.createTransport('SES', {
        AWSAccessKeyID: 'xxx', // real one in code
        AWSSecretKey: 'xxx', // real one in code
        ServiceUrl: 'email-smtp.us-west-2.amazonaws.com'
    });

    var message = {
        from: '[email protected]', // verified in Amazon AWS SES
        to: '[email protected]', // verified in Amazon AWS SES
        subject: 'testing',
        text: 'hello',
        html: '<p><b>hello</b></p>' +
              'test'
    };

    transport.sendMail(message, function(error) {
        if (error) {
            console.log(error);
        } else {
            console.log('Message sent: ' + response.message);
        }
    });

This code is part of a controller where all other functions within it work perfectly.

  • Is there something I am missing?
  • Perhaps I'm calling for the incorrect nodemailer module?
  • Or should the transport be SMTP, not SES?

I'm stuck.

like image 836
O P Avatar asked Jun 01 '14 17:06

O P


People also ask

Is Nodemailer an SMTP server?

SMTP is the main transport in Nodemailer for delivering messages. SMTP is also the protocol used between different email hosts, so its truly universal.

What is Nodemailer used for?

Nodemailer is a Node. js module that allows you to send emails from your server with ease. Whether you want to communicate with your users or just notify yourself when something has gone wrong, one of the options for doing so is through mail.


1 Answers

Please use aws-sdk directly. It work for me. Hope it will help you.`

let nodemailer = require('nodemailer');
let AWS = require('aws-sdk');

// configure AWS SDK
AWS.config.update({
  accessKeyId: << SES_ACCESS_KEY >>,
  secretAccessKey: << SES_SECRET_KEY >>,
  region: << SES_REGION >>,
});

// create Nodemailer SES transporter
let transporter = nodemailer.createTransport({
SES: new AWS.SES({
  apiVersion: '2010-12-01'
})
});

// send some mail
transporter.sendMail({
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Message',
  text: 'I hope this message gets sent!'
}, (err, info) => {
  console.log(info.envelope);
  console.log(info.messageId);
});
like image 97
Pramod Jaiswal Avatar answered Sep 26 '22 17:09

Pramod Jaiswal