下面的代码从服务器端发送邮件。如何在Angular 9应用程序中使用该代码.请你帮助一些人。
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: 'xxxx'
}
});
var mailOptions = {
from: '[email protected]',
to: '[email protected]',
subject: 'Sending Email using Node.js',
text: `Hi, thank you for your nice Node.js Email.`
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
也许,上面的代码会在Angular应用中工作,但这样做的最大问题是,你会在你的前台应用中暴露邮件传输凭证。如前所述,最好的解决方案是创建一个简单的API,在服务器端发送邮件。