【发布时间】: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