无法从任何提供商nodemailer aws加载凭据

时间:2017-08-09 19:29:59

标签: node.js amazon-web-services amazon-ec2 aws-sdk nodemailer

我一直试图找到问题的答案。我一直在尝试使用nodemailer和nodemailer-ses-transport。这是nodemailer代码:

var cfg = require('../config/config');
var nodemailer = require('nodemailer');
var aws   = require('nodemailer-ses-transport');

var transporter = nodemailer.createTransport(aws({
  accessKeyId: cfg.KEY,
  secretAccessKey: cfg.SKEY,
  default_region: cfg.REG,
  ratelimit: 5
}));

router.post('/signup', function(req, res, next){
  passport.authenticate('local.signup', function(err, user, info) {
    if (err) { return next(err); }
    // Redirect if it fails

    if (!user) { return res.redirect('/signup'); }
    req.logIn(user, function(err) {
     if (err) { return next(err); }
      // Redirect and send email if it succeeds

      var date = Date.now();

      var mailOptions = {
        from: cfg.USER,
        to: req.body.email,
        date: date,
        subject: 'Welcome to Shapevibe',
        html: '<p> Welcome to Shapevibe!</p>'
      };
      transporter.sendMail(mailOptions, function(error, info){
        if(error){
          console.log(error);
        }
        else{
          console.log('Message Sent: ' + info);
        }
      });
      return res.redirect('/api/dashboard/viber' + user._id);
    });

    // flash success and redirect to viber dashboard
    req.flash('success', 'Thank you for signing up. You will recieve 
an email shortly');
 })(req, res, next);
});

在配置文件中:

var config = {};
config.USER = 'Shapevibe@gmail.com';
config.KEY = 'xxxxxxxxxxx';
config.SKEY = 'xxxxx';
config.REG = 'us-west-2c';
module.exports = config;

当我运行npm start时,它很好地连接到服务器。但是,当我在第I页中测试登录时,路由工作正常,但电子邮件没有发送,我收到此错误:

{ CredentialsError: Missing credentials in config
    at IncomingMessage.<anonymous> 
(/home/ubuntu/ShapeVibe/Website/node_modules/aws-sdk/lib/util.js:864:34)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:188:7)
    at endReadableNT (_stream_readable.js:975:12)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickDomainCallback 
(internal/process/next_tick.js:128:9)
  message: 'Missing credentials in config',
  retryable: false,
  time: 2017-08-09T19:13:54.105Z,
  code: 'CredentialsError',
  originalError: 
   { message: 'Could not load credentials from any providers',
     retryable: false,
     time: 2017-08-09T19:13:54.105Z,
     code: 'CredentialsError' } }

I have been researching a solution for a long time now, and nothing has seemed to work. I looked at almost everything similar on Stackoverflow and nothing has helped. Please let me know if you have any ideas.

1 个答案:

答案 0 :(得分:1)

查看共享凭据文件

要使用凭证文件提供程序,只需按以下格式将访问密钥和密钥添加到〜/ .aws / credentials文件中:

[default]
aws_access_key_id = AKID...
aws_secret_access_key = YOUR_SECRET_KEY

如果您还没有此文件/目录,请不要担心 - 只需为自己创建它们。

您可以在此处了解详情:https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SharedIniFileCredentials.html