Skip to main content

Nodemailer

Nodemailer is a module that enables to send emails using SMTP protocol

Network Connection needs

This integration needs network access to the server where the service is running.

See the Network access page for details about how to achieve that.

Nodemailer snippets available in YepCode editor#

note

The title is the triggering text for YepCode to autocomplete the script

Integration#

New integration from credential
const nodemailerTransport = yepcode.integration.nodemailer('credential-slug')
New integration from plain authentication data
const nodemailer = require('nodemailer');
// create reusable transporter object using the default SMTP transportconst nodemailerTransport = nodemailer.createTransport({  host: "smtp.ethereal.email",  port: 587,  secure: false,  connectionTimeout: 100,  auth: {    user: "user",    pass: "password",  },});

Verify SMTP connection configuration#

Verify SMTP connection configuration (async/await)
// verify connection configurationtry {    const verified = await nodemailerTransport.verify()    console.log("Server is ready to take our messages");} catch (error) {    console.error(error);    throw error;}
Verify SMTP connection configuration (Promise)
// verify connection configurationnodemailerTransport.verify().then(() => {    console.log("Server is ready to take our messages");}).catch((error) => {    console.error(error);    throw error;});
Verify SMTP connection configuration (callback)
// verify connection configurationnodemailerTransport.verify(function(error, success) {  if (error) {    console.error(error);  } else {    console.log("Server is ready to take our messages");  }});

Send mail#

Send mail (async/await)

try {    const info = await nodemailerTransport.sendMail({        from: '"Fred Foo ๐Ÿ‘ป" <foo@example.com>', // sender address        to: "bar@example.com, baz@example.com", // list of receivers        subject: "Hello โœ”", // Subject line        text: "Hello world?", // plain text body        html: "<b>Hello world?</b>", // html body    })    console.log("Message sent: " + info.messageId);    console.log("Preview URL: " + nodemailer.getTestMessageUrl(info));} catch (error) {    console.error(error);    throw error;}
Send mail (Promise)
nodemailerTransport.sendMail({    from: '"Fred Foo ๐Ÿ‘ป" <foo@example.com>', // sender address    to: "bar@example.com, baz@example.com", // list of receivers    subject: "Hello โœ”", // Subject line    text: "Hello world?", // plain text body    html: "<b>Hello world?</b>", // html body}).then((info) => {    console.log("Message sent: " + info.messageId);    console.log("Preview URL: " + nodemailer.getTestMessageUrl(info));}).catch((error) => {    console.error(error);    throw error;});
Send mail (callback)
nodemailerTransport.sendMail({    from: '"Fred Foo ๐Ÿ‘ป" <foo@example.com>', // sender address    to: "bar@example.com, baz@example.com", // list of receivers    subject: "Hello โœ”", // Subject line    text: "Hello world?", // plain text body    html: "<b>Hello world?</b>", // html body}, (error, info) => {  if (error) {    console.error(error);  } else {    console.log("Message sent: " + info.messageId);    console.log("Preview URL: "  nodemailer.getTestMessageUrl(info));  }});