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使用