我在子域上构建了NodeJS服务器,并打算使用主域的电子邮件帐户发送电子邮件。nodemailer的配置设置如下:在此处输入图像描述
但每当我调用sendMail函数时,就会发送空电子邮件。我不确定问题出在哪里。请帮帮我,有人遇到过类似的问题吗?
如果您正在使用nodejs,您可以尝试使用Nodemailer。https://nodemailer.com/about/
Check out my code below, it is working with my Cpanel mail server.
const nodemailer = require("nodemailer");
async function main() {
let transporter = nodemailer.createTransport({
host: "yoursmtp server.yourdomain",
port: 465,
secure: true,
auth: {
user: "user",
pass: "password",
},
});
let info = await transporter.sendMail({
from: 'youremail@yourdomain.com',
to: "example@hotmail.com",
subject: "your subject",
text: "your body goes here ",
});
console.log("Message sent: %s", info.messageId);
console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
}
main().catch(console.error);