How to define custom domain email in nodemailer?

I'm trying to send email using Nodejs package Nodemailer, but i'm unable to change the from email to my custom domain email. Any help will be appreciated. here is the code i'm using to send an email.

transporter.sendMail({
   from: 'support@domain.com',
   to: 'recipient@example.com',
   subject: 'Message',
   text: 'I hope this message gets through!',
   auth: {
            user: 'zeshanvirk@gmail.com'
         }
});

1 answer

  • answered 2018-04-17 04:55 Vicky

    function sendEmail(to, subject, message, callback) {
        var transporter = nodemailer.createTransport({
            host: 'HOST_NAME',
            port: 'PORT',
            auth: {
                user: 'support@domain.com',
                pass: 'YOUR_PASSWORD'
            },
            secureConnection: 'false',
            tls: {
                ciphers: 'SSLv3'
            }
    
        });
    
        var mailOptions = {
           from: 'support@domain.com',
            to: 'recipient@example.com',//to,
            subject: 'Message',
            text: 'I hope this message gets through!'
    
        };
    
        transporter.sendMail(mailOptions, function (err, info) {
    
            if(err){
                console.log("sending email error:"+err);
            }
            if(callback){
                callback(err, info);
                console.log("email sent successfully");
            }
    
        })
    
    }