SMTP
Send emails using SMTP protocol
Tagsemailsmtp
- JavaScript
- Python
Documentationhttps://nodemailer.com/usage/
NodeJS packagehttps://www.npmjs.com/package/nodemailer
Version6.9.1
Source Codehttps://github.com/nodemailer/nodemailer
Documentationhttps://docs.python.org/3/library/smtplib.html
Pypi packagehttps://docs.python.org/3/library/smtplib.html
Version3.11
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.
- JavaScript
- Python
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));
}
});
Integration
New integration from credential
smtp = yepcode.integration.smtp('credential-slug')
New integration from plain authentication data
import smtplib
smtp = smtplib.SMTP("host", "port")
# If you need SSL
# smtp = smtplib.SMTP_SSL("host", "port")
smtp.login("username", "password")
# You should use a yepcode env variable to don't store plain password
# See: https://docs.yepcode.io/docs/processes/team-variables
Verify SMTP Connection Configuration
Verify SMTP connection configuration
smtp.noop()
Send Mail
Send mail (plain text)
try:
mail_content = "Subject: Mail subject\n\n"
mail_content += "Some message.\n"
smtp.sendmail("sender_email", "receiver_email", mail_content)
print("Email sent successfully!")
except Exception as e:
print(f"Error sending email: {e}")
Send mail
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
sender_email = "sender_email"
receiver_email = "receiver_email"
body = """
<h1>Hello from YepCode</h1>
<p>This is a test email sent using Python</p>
"""
message = MIMEMultipart()
message["From"] = sender_email
message["To"] = receiver_email
message["Subject"] = "Hello, World! Sent from YepCode"
message.attach(MIMEText(body, "html"))
try:
smtp.sendmail(sender_email, receiver_email, message.as_string())
print("Email sent successfully!")
except Exception as e:
print(f"Error sending email: {e}")