Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodemailer without Gmail

I'm using NodeJS and I want to configure my email account with Nodemailer.

All the Nodemailer examples that I found are for Gmail...

var transporter = nodemailer.createTransport({
    service: 'Gmail',
    auth: {
        user: '[email protected]',
        pass: 'userpass'
    }
});

How can I put another service? In special I bought a email domain in ovh (SSL0.OVH.NET) and I interested to configure this email account.

I tried but I don't found the way to get this...

Thank you!

like image 355
Aral Roca Avatar asked Oct 30 '25 10:10

Aral Roca


2 Answers

I create a module Mail for send html mails by SMTP

exports.send = function(email, subject, htmlcontent, callback) {
    var nodemailer = require('nodemailer');
    var smtpTransport = require('nodemailer-smtp-transport');
    var configMail = require('../bin/config').mail;//my json configurations mail

    var transporter = nodemailer.createTransport(smtpTransport({
        host: configMail.host, //mail.example.com (your server smtp)
        port: configMail.port, //2525 (specific port)
        secureConnection: configMail.secureConnection, //true or false
        auth: {
            user: configMail.auth.user, //[email protected]
            pass: configMail.auth.pwd //password from specific user mail
        }
    }));

    var mailOptions = {
        from: configMail.email,
        to: email,
        subject: subject,
        html: htmlcontent
    };

    transporter.sendMail(mailOptions, function(err, info){
        transporter.close();
        if(err) {
            callback(err, info);
        }
        else {
            callback(null, info);
        }
    });
}

The usage:

var Mail = require('../utils/Mail'); //require this module
Mail.send('[EMAIL TO SEND]', '[TITLE]', '[YOUR HTML TEMPLATE MAIL]', function(err, info) {
    if(err) {
        //error
    }
    else {
        //Email has been sent and you can see all information in var info
    }
});
like image 53
Joaquinglezsantos Avatar answered Nov 01 '25 22:11

Joaquinglezsantos


On creating an email id in the domain (mostly through c panel), check the mail configurations for that mail address and look for SMTP details such as port, username, etc. Then enter those details in the nodemailer transporter. For example, my transporter details were:

const transporter = nodemailer.createTransport({
    host: "mail.schoolprogramming.tech",
    port: 465,
    secure: true, // true for 465, false for other ports
    auth: {
      user: "[email protected]",
      pass: "**************"
    }
  });
like image 29
user12269532 Avatar answered Nov 02 '25 00:11

user12269532



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!