这是我的代码。当它在Postman中运行时,它会显示错误,例如无法获取方法。
var sendTempMail = function (req,res)
{
const nodemailer = require('nodemailer');
let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
auth: {
user: 'transactions@gmail.com',
pass: 'qwertyu@'
}
});
let mailOptions = {
from: 'transactions@gmail.com',
to: 'xxxxxx@gmail.com','yyyyyyyy@gmail.com',zzzzzz@mydomain.com,//here to:receiver not accept more than one
subject: 'mail notification Test',
text: 'Hello !!!!!!!!!everything works fine'
html:<h1>Notification mail</h1>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 10px;
text-align: left;
}
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log("mail not sent" +error.message);
}
console.log('success');
});
};
module.exports = {
newTemplate :newTemplate,
sendTempMail : sendTempMail
};
答案 0 :(得分:0)
请将您的错误消息粘贴到您的问题中。但是,我可以看到一个错误,HTML参数已粘贴所有原始html。它应该是字符串格式。
请在下面的代码中查看第44行 https://github.com/nodemailer/nodemailer/blob/master/examples/full.js