Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Nodejs+nodemailer send mail

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is about how Nodejs+nodemailer sends emails. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Characteristics

Zero dependency on a single module-the code is easy to audit because there is no dark corner. [recommended: "nodejs tutorial"]

Highly concerned about security, no one likes RCE vulnerabilities.

Unicode supports the use of any character, including emoji

Windows support-you can install it above sea level on Windows, just like any other module, without compiling dependencies. Use it easily from an Azure or Windows box

Use HTML content and plain text substitution

Add attachment messa

Image attachment for embedded HTML content-your design will not be blocked

Use TLS/STARTTLS to securely send email *

Different modes of transportation in addition to built-in SMTP support

Custom plug-in support for processing messages

Rational OAuth3 verification

Proxy is used for SMTP connection

ES6 code-no more unintentional memory leaks due to hoisting VAR

The mail has been encapsulated and sent using different SMTP mail servers. Send email messages of any content / / introduction module nodemailerconst nodemailer = require ('nodemailer') const partnerEmail = {"QQ": {"host": "smtp.qq.com", "port": 465, "user": "", "pass": "}," 12661 "host": "smtp.126.com", "port": 465, "user": "" "pass": "smtp.163.com", "port": 465, "user": "", "pass": "} const config = {/ 163mailbox smtp.163.com host: partnerEmail.QQ.host,// this is QQ Mail / / port port: partnerEmail.QQ.port Auth: {/ / sender mailbox account number user: partnerEmail.QQ.user, / / the authorization code of the sender mailbox can be obtained here through QQ Mail and is not unique pass: partnerEmail.QQ.pass}} / / send email function sendMail with attachments (email Code) {/ / code verification code const transporter = nodemailer.createTransport (config) const mail = {/ / sender mailbox 'nickname' from:', / / subject subject: 'activation verification code', / / the recipient's mailbox can be another mailbox, not necessarily QQ Mail to: email, / / content text: `Your activation verification code is: ${verification} Please be valid within 3 minutes. Please keep it carefully. `, / / you can add html tags html: 'baidu', attachments: [{"filename": "xxx.mp3", "path": ". / xxx.mp3"}, {"filename": "xxx.txt", "content": "File"}, {"filename": "xxx.JPG", "path": ". / xxx.JPG" "cid": "01" / / Picture inserted in the body of the message}]} return new Promise ((resolve, reject) = > {transporter.sendMail (mail, function (error, info) {error? Reject (error): resolve (info.response) transporter.close ()})} exports.sendMail = sendMail` Thank you for reading! This is the end of the article on "how to send email on Nodejs+nodemailer". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report