【问题标题】:Mailgun - Unauthenticated email from guest.comMailgun - 来自 guest.com 的未经身份验证的电子邮件
【发布时间】:2018-12-08 02:01:15
【问题描述】:

我使用 nodemailer 在我的 node.js 中设置了 mailgun,当我使用我的 REST 客户端测试我的路由时,我无法让它发送电子邮件。当我直接将代码写入服务器文件时,电子邮件会在服务器启动时立即发送。

但是,当我在 app.post 中编写电子邮件 api 并使用 REST 客户端对其进行测试时,电子邮件在 mailgun 端失败并被谷歌拒绝???这只是我的假设,因为我得到了错误代码。

Server response: 550 5.7.1 Unauthenticated email from guest.com is not 
accepted due to domain's 5.7.1 DMARC policy. Please contact the administrator 
of guest.com domain if 5.7.1 this was a legitimate mail. Please visit 5.7.1 
https://support.google.com/mail/answer/2451690 to learn about the 5.7.1 DMARC 
initiative. s12-v6si3013316qtg.362 - gsmtp

我已经按照提供的链接进行操作,并且文档说要与域服务器核对。我不明白为什么会收到此错误,因为我已经在 mailgun 中验证了我的 gmail。

我也尝试过直接使用 mailgun-js 中间件。在 mailgun.com 上找到了三个不同的 mailgun-js api,在 github 上找到了 mailgun-js,在 npmjs.com 上找到了 mailgun-js。得到与上面相同的错误。

不知所措。不知道该怎么办。

我的 nodemailer 代码:

const express = require('express');
const nodemailer = require('nodemailer');
const path = require('path');
const bodyParser = require('body-parser');    


const app = express();

const port = 3000;

app.use(bodyParser.json());

app.use(express.static(path.join(__dirname, 'dist')));       

app.post('/email', (req, res) => {
  let transporter = nodemailer.createTransport({
          host: 'smtp.mailgun.org',
          port: 587,
          secure: false, // true for 465, false for other ports
          auth: {
              user: 'postmaster@sandboxc8f2ecf64f364ca6ad740e658485c557.mailgun.org',
              pass: 'my API key here'
          },
          tls: {
            rejectUnauthorized: false
          }
      });

      // setup email data with unicode symbols
      let mailOptions = {
          from: req.body.from, // sender address
          to: 'cu0ngpitt@gmail.com', // list of receivers
          subject: 'Someone wrote you from your Online Resume!', // Subject line
          text: req.body.messge, // plain text body
      };

      // send mail with defined transport object
      transporter.sendMail(mailOptions, (error, info) => {
          if (error) {
              return console.log(error);
          }
          console.log('Message sent: %s', info.messageId);
          console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
      });
});

app.get('/', (req, res) => {
  res.send('Hello world');
});

app.listen(port, () => {
  console.log('Server running on port ' + port);
})

【问题讨论】:

  • 我不知道“我已经在 mailgun 中验证了我的 gmail”是什么意思。您了解 DKIM 签名以及 DMARC 的工作原理吗?

标签: node.js mailgun nodemailer


【解决方案1】:

Mailgun 回复了我的请求并说由于 DMARC 安全性,我只能发送与我的 mailgun 帐户具有相同域的电子邮件。

因为我有一个免费的 mailgun 帐户。我不得不将我的发件人地址更改为我的免费 mailgun 地址,即 postmaster@sandbox"some long string".mailgun.org

如果使用 nodemailer,您可以省略发件人电子邮件或将其硬编码。

如果使用 mailgun-js,你必须硬编码。

我的旧代码:

// setup email data with unicode symbols
      let mailOptions = {
          from: req.body.from, // sender address
          to: 'cu0ngpitt@gmail.com', // list of receivers
          subject: 'Someone wrote you from your Online Resume!', // Subject line
          text: req.body.messge, // plain text body
      };

更正的代码:

// setup email data with unicode symbols
      let mailOptions = {
          postmaster@sandbox"some long string".mailgun.org, // sender address
          to: 'cu0ngpitt@gmail.com', // list of receivers
          subject: 'Someone wrote you from your Online Resume!', // Subject line
          text: req.body.messge, // plain text body
      };

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-10
    • 2020-06-22
    • 1970-01-01
    • 1970-01-01
    • 2021-07-21
    相关资源
    最近更新 更多