Nodemailer和Amazon SES [英] Nodemailer and Amazon SES

查看:180
本文介绍了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?

我被卡住了。

推荐答案

以下代码是我使用的,它对我有用。这适用于当前的NodeMailer。需要单独包含运输模块的地方。在之前的版本中,传输模块是内置的。
https://andrisreinman.com / nodemailer-v1-0 / #migrationguide

The below code is what I used and it worked for me. This is for the current NodeMailer. Where the transport module needs to be included separately. In the previous versions the transport modules were built in. https://andrisreinman.com/nodemailer-v1-0/#migrationguide

var nodemailer = require('nodemailer');
    var sesTransport = require('nodemailer-ses-transport');

    var SESCREDENTIALS = {
      accessKeyId : "accesskey" ,
      secretAccessKey : "secretkey"
    };

    var transporter = nodemailer.createTransport(sesTransport({
        accessKeyId: SESCREDENTIALS.accessKeyId,
        secretAccessKey: SESCREDENTIALS.secretAccessKey,
        rateLimit: 5
    }));



      var mailOptions = {
          from: 'FromName <registeredMail@xxx.com>',
          to: 'registeredMail@xyz.com', // list of receivers
          subject: 'Amazon SES Template TesT', // Subject line
          html: <p>Mail message</p> // html body
      };

      // send mail with defined transport object
      transporter.sendMail(mailOptions, function(error, info){
          if(error){
              console.log(error);
          }else{
              console.log('Message sent: ' + info);
          }
      });

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

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