NOTICE: Trial account does not have SMTP service. Therefore, you cannot test this in your trial account. We do this to prevent spammer from taking advantage of our Free Trial Service.
You should use the smtp server assigned to your account "mail.yourdomain.com" as the SMTP outgoing server for your web applications(Replace yourdomain.com to your own domain name).
To get your SMTP server setup, please follow the below:
1) Login to your control panel
2) Make sure a domain name is added to your account by going to Hosting Control Panel -> Website Domain Manager
3) Once the domain name is added to your account, go to Hosting Control Panel -> Email Manager and activate your email service for your domain name.
4) Create the necessary email account that you need. Your script MUST send from an valid Email account. So create the ones you need.
5) Done! Please follow below's code sample to send emails.
YOU MUST USE SMTP AUTHENTICATION
Note: you have to get Nodemailer from https://github.com/nodemailer/nodemailer and install it to your local nodejs application. Or run NPM installer to install the package.
>cd NodeAppFolder
>NPM install nodemailer
Sample code
'use strict';
const nodemailer = require('nodemailer');
// async..await is not allowed in global scope, must use a wrapper
async function main() {
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: 'mail.domain.com', //mail server name
port: 25, //TLS port is 587
secure: false, // true for 465, false for other ports
auth: {
type: "login",
user: '[email protected]', // real email user
pass: 'secret' // email password
},
tls: {
// do not fail on invalid certs
rejectUnauthorized: false
},
ignoreTLS: false // if this is true and secure is false
// then TLS is not used
// even if the server supports STARTTLS extension
});
// send mail with defined transport object
let info = await transporter.sendMail({
from: '"Name" <[email protected]>', // sender address, MUST match auth.user
to: '[email protected]', // list of receivers, separate using comma
subject: 'Here is the subject', // Subject line
text: 'This is the body in plain text', // plain text body
html: '<b>This is the HTML message</b>' // html body
});
console.log('Message sent: %s', info.messageId);
// Message sent: <[email protected]>
// Preview only available when sending through an Ethereal account
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
}
main().catch(console.error);
Article ID: 1996, Created: October 10, 2019 at 11:26 PM, Modified: October 12, 2019 at 1:40 AM