【问题标题】:Nodemailer and MailgunNodemailer 和 Mailgun
【发布时间】:2014-04-27 18:58:29
【问题描述】:

在将 Nodemailer 与 Mailgun 一起使用时,我遇到了身份验证错误。 Nodemailer 文档指出该库可以很好地与 Mailgun SMTP 配合使用,但是在运行我的应用程序时我不断收到此错误:

{ [AuthError: Invalid login - *** *.*.* Mailgun is not loving your login or password]
  name: 'AuthError',
  data: '*** *.*.* Mailgun is not loving your login or password',
  stage: 'auth' }

这就是我设置运输的方式:

@Transport = nodemailer.createTransport("SMTP",
     service: "Mailgun"
     auth:
         user: "api"
         pass: "**********************"
)

我 100% 确定我的 api 密钥是正确的。我还缺少其他要求吗?

不管怎样,当我使用 Gmail 地址时,它可以完美运行。

【问题讨论】:

    标签: javascript node.js coffeescript mailgun nodemailer


    【解决方案1】:
    var nodemailer = require('nodemailer');
    var mg = require('nodemailer-mailgun-transport');
    
    // This is your API key that you retrieve from www.mailgun.com/cp (free up to 10K monthly emails)
    var auth = {enter code here
      auth: {`enter code here`
        api_key: 'key-1234123412341234',
        domain: 'one of your domain names listed at your https://mailgun.com/app/domains'
      }
    }
    
    var nodemailerMailgun = nodemailer.createTransport(mg(auth));
    
    nodemailerMailgun.sendMail({
      from: 'myemail@example.com',
      to: 'recipient@domain.com', // An array if you have multiple recipients.
      cc:'second@domain.com',
      bcc:'secretagent@company.gov',
      subject: 'Hey you, awesome!',
      'h:Reply-To': 'reply2this@company.com',
      //You can use "html:" to send HTML email content. It's magic!
      html: '<b>Wow Big powerful letters</b>',
      //You can use "text:" to send plain-text content. It's oldschool!
      text: 'Mailgun rocks, pow pow!'
    }, function (err, info) {
      if (err) {
        console.log('Error: ' + err);
      }
      else {
        console.log('Response: ' + info);
      }
    });
    

    【讨论】:

      【解决方案2】:

      您可以使用https://github.com/orliesaurus/nodemailer-mailgun-transport 使用 API 而不是 SMTP 发送电子邮件。

      var nodemailer = require('nodemailer');
      var mg = require('nodemailer-mailgun-transport');
      
      var auth = {  auth: {
      api_key: 'key-1234123412341234',
      domain: 'one of your domain names listed at your https://mailgun.com/app/domains'}}
      

      【讨论】:

      • OP 确实需要使用 SMTP 传输
      【解决方案3】:

      您不能将 api 密钥用于 smtp 传输。

      转到 mailgun 控制台并从域配置中获取 smtp 凭据并使用这些凭据。

      【讨论】:

        猜你喜欢
        • 2018-04-03
        • 2016-09-24
        • 1970-01-01
        • 1970-01-01
        • 2015-10-10
        • 2015-01-13
        • 1970-01-01
        • 2020-07-12
        • 1970-01-01
        相关资源
        最近更新 更多