我想通过我的下一个js网站发送交易电子邮件给用户的通讯和重置密码的目的,我正在使用SMTP凭据Nodemailer.使用Mailgun,Sendinblue,MSG 91,邮戳(所有与免费计划),但要么我的邮件去积压或排队.
我也试过Sendinblue的API但还是遇到了同样的问题,没有一封邮件进入收件人的邮箱。你可以在下面看到完整的响应和API;
这是我的API,跳过注解逻辑,跳到nodemailer部分
import ConnectDB from "@/utils/connect_db"
import User from "@/models/user"
const nodemailer = require('nodemailer');
const jwt = require("jsonwebtoken")
const forgotPassword = async (req, res) =\> {
try {
if (req.method === 'POST') {
await ConnectDB()
// let user = await User.findOne({ email: req.body.email })
// if (!user) user = await User.findOne({ username: req.body.email }) //because user can put the username or email in the same field and api should verify from both ways
// if (!user) return res.status(404).json({ success: false, msg: "You don't have an account with this email!" })
// const token = jwt.sign({ id: user._id }, process.env.SECRET_KEY, { expiresIn: '2m' })
// USING Postmark
const transport = nodemailer.createTransport({
host: "smtp.postmarkapp.com",
port: 587,
auth: {
user: "34dd6ee8-8015-444a-92e5-25194cf742cc",
pass: "34dd6ee8-8015-444a-92e5-25194cf742cc"
}
});
// create email message object
const message = {
from: 'binarshadsaad6@gmail.com',
to: 'saad19rsf@gmail.com',
text: "hellow this is a text email body to check the email service",
subject: 'You subscribed our Newsletter',
html: `<html><body><h1>Fitte Moooo!</h1><p>Dear valuable Jheengu this email is to notify you that you have successfully recieved the 'Fitte Moo' reward for literally just existing at this time of morning.</p></body></html>`
};
// send email using nodemailer
let info = await transport.sendMail(message);
console.log(info)
res.json({ success: true, info })
}
else {
res.status(400).json({ success: false, msg: "bad request, you are using wrong request method!" })
}
}
catch (error) {
console.log(error)
res.status(500).json({ success: false, msg: "Internal server error occurred, pleae try again later" })
}
}
export default forgotPassword
这是我点击API时的完整回应
{
"success": true,
"info": {
"accepted": [
"saad19rsf@gmail.com"
],
"rejected": [],
"ehlo": [
"PIPELINING",
"SIZE 20480000",
"VRFY",
"ETRN",
"AUTH PLAIN LOGIN CRAM-MD5 DIGEST-MD5",
"AUTH=PLAIN LOGIN CRAM-MD5 DIGEST-MD5",
"ENHANCEDSTATUSCODES",
"8BITMIME",
"DSN"
],
"envelopeTime": 622,
"messageTime": 452,
"messageSize": 858,
"response": "250 2.0.0 Ok: queued as 3B28D414C40",
"envelope": {
"from": "binarshadsaad6@gmail.com",
"to": [
"saad19rsf@gmail.com"
]
},
"messageId": "<50a33941-a951-b4eb-2290-781a58eda83d@gmail.com>"
}
}
1条答案
按热度按时间gev0vcfq1#
我在Postmark工作,虽然我的技术还不足以解决您的代码问题,但我可以提供一些其他的见解:如果您使用Postmark免费计划,则只有在您的帐户获得批准(more detail on that here)后,您才能向自己的域发送电子邮件。否则,您的电子邮件将如此处所示排队。我们的支持团队也很乐意为您提供帮助-您可以通过support@postmarkapp.com与他们联系。