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.
I'm stuck.
SMTP is the main transport in Nodemailer for delivering messages. SMTP is also the protocol used between different email hosts, so its truly universal.
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.
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);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With