Node Mailer Error:“Unsupported configuration, down

2020-02-29 03:03发布

I am new to nodejs and try to send mail from nodemailer module but it has error i.e "Unsupported configuration, downgrade Nodemailer to v0.7.1 to use it".

Here is my code:-

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);
});

2条回答
家丑人穷心不美
2楼-- · 2020-02-29 03:27

To use nodemailer v1, try to implement this code.

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");
});
查看更多
倾城 Initia
3楼-- · 2020-02-29 03:28

You can try this one with Nodemailer V0.7.1. It worked for me.

var express = require('express');

var bodyParser = require('body-parser');

var app = express();

app.use(bodyParser());

app.get('/', function(req, res) {

    var html = '<form action="/" method="post">' +
        'Enter Email id:' +
        '<input type="text" name="userEmail"placeholder="Email" />' +
        '<br>' +
        '<button type="submit">Submit</button>' +
        '</form>';

    res.send(html);
});
app.post('/', function(req, res) {

    var userEmail = req.body.userEmail;

    var nodemailer = require('nodemailer');

    var transporter = nodemailer.createTransport("SMTP", {
        host: 'smtp.gmail.com',
        secureConnection: false,
        port: 587,
        auth: {
            user: 'dhruv******@gmail.com', //Sender Email id
            pass: '**********' //Sender Email Password
        }
    });

    var mailOptions = {
        from: 'dhruv*******@gmail.com', // sender address
        to: 'dhaval********@gmail.com', // list of receivers
        subject: 'Message Form ' + userEmail, // Subject line
        text: 'Hi....' + userEmail // plaintext body

    };

    transporter.sendMail(mailOptions, function(error, info) {
        if (error) {
            return console.log(error);
        }
        console.log('Message sent: ' + info.response);
        var html = 'Hello: ' + userEmail + '.<br>' +
            '<a href="/">Try again.</a>';
        res.send(html);
    });

});

app.listen(80);
查看更多
登录 后发表回答