nodejs学习 发送邮件

1、SMTP,MSA和MTA

           发送邮件的通用语言为简单邮件传输协议smtp

           邮件提交代理MSA会通过可靠的渠道投递邮件,降低被标为垃圾邮件的可能

            mta提供将邮件真正传输到最终目的地的服务

2、邮件组成

                邮件信息有两部分组成头部和主体

                            头部包含和邮件有关的信息:谁发的,发给谁,接收日期,主题等

3、nodemailer

            安装nodemailer的包

                            npm install nodemailer

            创建一个nodemailer实例

                       var mailTransport = nodemailer.createTransport("SMTP",{
                        host:"smtp.163.com",
                         port:465,
                         secure:true,
                         auth:{
                         user:credentials.gmail.user,
                         password:credentials.gmail.password,
                         }

                         });

            发送邮件

                    mailTransport.sendMail({
                            from:"[email protected]",
                            to:"[email protected]",

                             subject:"test",

                             text:"this is a test",

                      },function(err){
                                 if(err)
                                         console.log("unable to send email"+error);
                     });

你可能感兴趣的:(nodejs学习 发送邮件)