Skip to main content

SMTP

Send emails using SMTP protocol

Tagsemailsmtp
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.

Credential configuration

To configure this credential, you need the host, port, username and password to connect to the SMTP server.

Here is an example of a filled credential configuration form in YepCode:

SMTP Snippets available in Editor

note

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

Integration

New integration from credential
const nodemailerTransport = yepcode.integration.smtp('credential-slug')
tip

With Nodemailer, you can set any of the extra config params you can see here using credential extended options.

You also may look to other transport protocols if you need it.

New integration from plain authentication data
const nodemailer = require('nodemailer');

// create reusable transporter object using the default SMTP transport
const 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 configuration
try {
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 configuration
nodemailerTransport.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 configuration
nodemailerTransport.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: " + nodemailerTransport.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: " + nodemailerTransport.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: " nodemailerTransport.getTestMessageUrl(info));
}
});