I am new to testcafe
and Node.js and I want to send mail using nodemailer
. Can someone give me the steps? I tried few I am not sure if I am doing something incorrectly.
Here are the steps that followed:
npm install nodemailer
sendMail()
method of your previously created transporter:var mailer = require("nodemailer");
var transporter = mailer.createTransport({
host: "smtp.abc.email",
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: "email@abc.com", //
pass: "password" //
}
});
// send mail with defined transport object
var mail = {
from: "email@abc.com", // sender address
to: "email@abc.com", // list of receivers
subject: "hello", // Subject line
text: "Hello world?", // plain text body
html: "<b>Hello world?</b>" // html body
};
transporter.sendMail(mail, function(error, response) {
if (error) {
console.log(error);
} else {
console.log("Message sent: " + response.message);
}
transporter.close();
});
I have the following questions:
For SMTP do I need to install anything from npm?
Most of the examples in net shows Gmail, but I replace it with my company mail, I have considered here as smtp.abc.com
do I need to do anything else?
I want to send mail from my company email, what different setting is needed for that?
- For SMTP do I need to install anything from npm?
No. Only nodemailer
- I want to send mail from my company email, what different setting is needed for that?
import * as nodeMailer from "nodemailer";
const MAILER_CONFIG = Object.freeze({
host: "smtp.mycompany.com",
port: 25,
secure: false, // true for 465 SMTP port, otherwise false
auth: {
user: "username",
pass: "password"
}
});
const MAIL_OPTIONS = Object.freeze({
from: mailSender,
to: mailReceiver,
subject: mailSubject,
text: mailBodyText,
html: mailBodyHTML
});
const TRANSPORTER = Object.freeze(nodeMailer.createTransport(MAILER_CONFIG));
const mailSendingResult = await TRANSPORTER.sendMail(MAIL_OPTIONS);
TRANSPORTER.close();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.