vineet sah vineet sah - 1 month ago 65
Node.js Question

Node Mailer Error:"Unsupported configuration, downgrade Nodemailer to v0.7.1 to use it" in localhost

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

Answer

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