nodemailer使用
Prerequisite:
先决条件:
How to send emails using Nodemailer | Node.js
如何使用Nodemailer发送电子邮件。 Node.js
How to send emails with attachments using Nodemailer | Node.js
如何使用Nodemailer发送带有附件的电子邮件。 Node.js
This time around, we will see how to compose or build/format our email body using HTML?
这次,我们将看到如何使用HTML编写或构建/格式化电子邮件正文?
Code:
码:
// load the node mailer module
var nodemailer = require('nodemailer');
//configure the transporter
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: 'your gmail password'
}
});
//email options
var mailOptions = {
from: '[email protected]',
to: '[email protected]',
subject: 'Sending Email using Node.js',
html: '<h1> Node JS </h1> <br> <h5> Hello World</h5>'
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent');
}
});
Note: You can use the same format and send as many attachments as possible. Make sure the closing curly bracket of each attachment is separated by a comma sign (,).
注意:您可以使用相同的格式并发送尽可能多的附件。 确保每个附件的大括号用逗号(,)分隔。
Finally, start your node app and if sending is successful, the phrase ‘email sent' will be printed out on the console or terminal.
最后,启动您的节点应用程序,如果发送成功,则将在控制台或终端上打印出短语“已发送电子邮件”。
Check you're the email's inbox.
检查您是否是电子邮件的收件箱。
Using Gmail as your transporter, you can also enable the less secure app access setting.
使用Gmail作为传输者,您还可以启用安全性较低的应用访问设置。
Sending email requires internet connection.
发送电子邮件需要互联网连接。
Do not fear about your password security. It's a tested and secured module used by many since 2010.
不要担心您的密码安全性。 自2010年以来,它已被许多人使用并经过测试和保护。
Thanks for coding with me! See you @ the next article. Feel free to drop a comment or question.
感谢您与我编码! 下次见。 随意发表评论或问题。
翻译自: https://www.includehelp.com/node-js/how-to-send-emails-with-nodemailer-using-html-as-content-node-js.aspx
nodemailer使用