Just like it is pointed out in the nodemailer documentation https://nodemailer.com/smtp/
You need to configure a transporter with your custom domain info (host, port, user and password) You can find this info in the email configuration of your specific hosting provider.
var transporter = nodemailer.createTransport({
host: 'something.yourdomain.com',
port: 465,
secure: true, // true for 465, false for other ports
auth: {
user: 'username@mydomain.com', // your domain email address
pass: 'password' // your password
}
});
Then you can go on and define the mail options:
var mailOptions = {
from: '"Bob" <bob@bobsdomain.com>',
to: 'tom@gmail.com',
subject: "Hello",
html : "Here goes the message body"
};
Finally you can go on and use the transporter and mailOptions to send an email using the function sendEmail
transporter.sendMail(mailOptions, function (err, info) {
if (err) {
console.log(err);
return ('Error while sending email' + err)
}
else {
console.log("Email sent");
return ('Email sent')
}
});