gpt4 book ai didi

javascript - Centos服务器中的Nodemailer,电子邮件发送但不接收

转载 作者:行者123 更新时间:2023-12-02 22:56:05 27 4
gpt4 key购买 nike

我在centos服务器上有一个代码,有一个使用nodemailer发送电子邮件的代码,响应是200,但电子邮件没有收到

这是我的代码

var transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
port: 465,
secure: true,
auth: {
user: 'xxx@gmail.com',
pass: 'xxx'
}
});

var mailOptions = {
from: 'xxxgmail.com',
to: email,
subject: 'Blablabla',
// text: 'That was easy!'
html: html_export,
attachments: [
{ // utf-8 string as an attachment
filename: 'logo.png',
path: path_logo,
cid: 'unique@kreata.ee'
},
{ // binary buffer as an attachment
filename: 'logo.pdf',
path: 'uploads/' + outpath
}
]
};

transporter.sendMail(mailOptions, (err, info) => {
if (err) {
return res.send({ status: 404, message: 'Send Email Failed' });
} else {
return res.send({ status: 200, message: 'Send Email Success' });
}
});

最佳答案

试试这个:

import * as nodemailer from 'nodemailer';

export const sendEmail = async () => {
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: your_email,
pass: your_password
}
});
const mailContent = {
from: '"johndoe.com" <johndoe@gmail.com>', // sender address
to: some.email@gmail.com, // list of receivers
subject: 'subject', // Subject line
text: '', // plain text body
html: `
<html>
<body style="text-align: center;">
<p>some text</p>
</body>
</html>` // html body
};

// send mail with defined transport object
try {
const info = await transporter.sendMail(mailContent);
console.log('Message sent: %s', info.messageId);
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
} catch (err) {
console.log(err);
}
};

这段代码不久前对我来说确实有效......

关于javascript - Centos服务器中的Nodemailer,电子邮件发送但不接收,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57973444/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com