Nodemailer 和 Amazon SES [英] Nodemailer and Amazon SES

查看:53
本文介绍了Nodemailer 和 Amazon SES的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的结构:

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: 'example@mail.com', // verified in Amazon AWS SES
        to: 'example@mail.com', // 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.

  • 有什么我遗漏的吗?
  • 也许我调用的 nodemailer 模块不正确?
  • 或者传输应该是 SMTP 而不是 SES?

我被卡住了.

推荐答案

请直接使用 aws-sdk.它对我有用.希望能帮到你.`

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: 'sender@example.com',
  to: 'recipient@example.com',
  subject: 'Message',
  text: 'I hope this message gets sent!'
}, (err, info) => {
  console.log(info.envelope);
  console.log(info.messageId);
});

这篇关于Nodemailer 和 Amazon SES的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆