nodemailer使用_如何使用Nodemailer发送电子邮件。 Node.js

nodemailer使用

Nodemailer is an npm module used to send emails. It has made the process of sending emails very easy.

Nodemailer是一个npm模块,用于发送电子邮件 。 它使发送电子邮件的过程变得非常容易。

Just like any other npm module, it is installed via npm using the command line.

与其他任何npm模块一样 ,它是使用命令行通过npm安装的。

Note: You should have a basic understanding of Node.js, Express and HTML.

注意:您应该对Node.js,Express和HTML有基本的了解。

Nodemailer has so many features and options which makes it interesting sending mails.

Nodemailer具有如此众多的功能和选项,这使得发送邮件变得很有趣。

It is very flexible with all the protocol required for sending mails and can equally be integrated with email services.

它非常灵活,可以发送邮件所需的所有协议,并且可以与电子邮件服务集成在一起。

One can begin sending/testing via the command line before actually creating a message form.

在实际创建消息表单之前,可以通过命令行开始发送/测试。

This article with gets you started with Nodemailer module.

本文与您一起开始使用Nodemailer模块

Essentials

必需品

The developers of Nodemailer module say the following is required in your code,

Nodemailer模块的开发人员说,您的代码中需要以下内容,

nodemailer 1

The transporter is the service that carries your mail. For example in our example, we will use Gmail.

运输者是承载您的邮件的服务。 例如,在我们的示例中,我们将使用Gmail。

Quickly install Nodemailer by opening a terminal and typing npm install nodemailer.

通过打开终端并键入npm install nodemailer来快速安装Nodemailer 。

Now, let's write our very first code.

现在,让我们编写第一个代码。

Open a text editor and type the following code: save the file as app.js

打开一个文本编辑器,然后输入以下代码:将文件另存为app.js

var nodemailer = require('nodemailer');  

//setup the transporter
var transporter = nodemailer.createTransport({
  service: 'gmail',
  auth: { //  your gmail credentials to use it's service
    user: '[email protected]',
    pass: 'yourpassword'
  }
});

var mailOptions = {
  from: '[email protected]',  //sending from,
  to: '[email protected]',   // sending to
  subject: 'testing nodemailer',  // subje ct of your mail
  text: 'We Thank God it works'  // body of mail
};

transporter.sendMail(mailOptions, function(error, info){
  if (error) {
    console.log(error);
  } else {
    console.log('Email Sent ' );
  }
});

Finally, start your node app and if sending is successful, the phrase 'email sent' will be printed out on the console or terminal.

最后,启动您的节点应用程序,如果发送成功,则将在控制台或终端上打印出短语“已发送电子邮件”

nodemailer 2

Check you're the email's inbox.

检查您是否是电子邮件的收件箱。

Using Gmail as your transporter, you can also enable the less secure app access setting.

使用Gmail作为传输工具,您还可以启用安全性较低的应用程序访问设置

nodemailer 3

Note:

注意:

Sending email requires internet connection.. hahaha. I got someone there!! So you thought this will work offline huh!

发送电子邮件需要互联网连接..哈哈哈。 我在那里有人!! 所以你以为这可以脱机工作吧!

Do not fear about your password security. It's a tested and secured module used by many since 2010.

不要担心您的密码安全性。 自2010年以来,它已被许多人使用并经过测试和保护。

To send to multiple recipients, simply add a comma sign after the first email you were sent to and continue adding other email addresses.

要发送给多个收件人,只需在发送给您的第一封电子邮件之后添加一个逗号符号,然后继续添加其他电子邮件地址。

to: '[email protected], [email protected]'

到:' [受电子邮件保护][受电子邮件保护] '

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-using-nodemailer-node-js.aspx

nodemailer使用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值