node.js – 节点邮件程序错误:“不支持的配置,将Nodemailer降级到v0.7.1以使用它”在localhost中

我是nodejs的新手,并尝试从nodemailer模块发送邮件,但它有错误,即“不支持的配置,将Nodemailer降级到v0.7.1以使用它”.

这是我的代码: –

var nodemailer = require('nodemailer');
var mailTransport = nodemailer.createTransport('SMTP',{
    service: 'Gmail',auth: {
        user: 'xxxxxxxx@gmail.com',pass: 'xxxxxxxxx',}
});

mailTransport.sendMail({
    from: '"ABC" <info@xxxx.example.com>',to: 'abcsss@xxx.example.com',subject: 'Test',text: 'Thank you for contact.',},function (err) {
    if (err)
        console.error('Unable to send email: ' + err);
});

解决方法

要使用nodemailer v1,请尝试实现此代码.

var express = require('express');
var nodemailer = require("nodemailer");
var smtpTransport = require("nodemailer-smtp-transport")
var app = express();

var smtpTransport = nodemailer.createTransport(smtpTransport({
    host : "YOUR SMTP SERVER ADDRESS",secureConnection : false,port: 587,auth : {
        user : "YourEmail",pass : "YourEmailPassword"
    }
}));
app.get('/send',function(req,res){
    var mailOptions={
        from : "YourEmail",to : "Recipient'sEmail",subject : "Your Subject",text : "Your Text",html : "HTML GENERATED",attachments : [
            {   // file on disk as an attachment
                filename: 'text3.txt',path: 'Your File path' // stream this file
            }
        ]
    }
    console.log(mailOptions);
    smtpTransport.sendMail(mailOptions,function(error,response){
        if(error){
            console.log(error);
            res.end("error");
        }else{
            console.log(response.response.toString());
            console.log("Message sent: " + response.message);
            res.end("sent");
        }
    });
});

app.listen(3000,function(){
    console.log("Express Started on Port 3000");
});

相关文章

这篇文章主要介绍“基于nodejs的ssh2怎么实现自动化部署”的...
本文小编为大家详细介绍“nodejs怎么实现目录不存在自动创建...
这篇“如何把nodejs数据传到前端”文章的知识点大部分人都不...
本文小编为大家详细介绍“nodejs如何实现定时删除文件”,内...
这篇文章主要讲解了“nodejs安装模块卡住不动怎么解决”,文...
今天小编给大家分享一下如何检测nodejs有没有安装成功的相关...