All SMTP Zen mailboxes can send mail through our SMTP cluster. These examples show how to authenticate securely from server-side applications. Replace the placeholders with your own hostname, mailbox, and password.
orion.smtpzen.com or your issued mail.domain.com).[email protected]).Store credentials in environment variables or secrets managers rather than committing them to source control.
import nodemailer from 'nodemailer'
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: 465,
secure: true,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS
}
})
await transporter.sendMail({
from: '[email protected]',
to: '[email protected]',
subject: 'Deployment complete',
text: 'The latest build has been deployed successfully.'
})
import os
import smtplib
from email.message import EmailMessage
msg = EmailMessage()
msg["Subject"] = "Nightly job finished"
msg["From"] = "[email protected]"
msg["To"] = "[email protected]"
msg.set_content("Backup completed without errors.")
with smtplib.SMTP_SSL(os.environ["SMTP_HOST"], 465) as smtp:
smtp.login(os.environ["SMTP_USER"], os.environ["SMTP_PASS"])
smtp.send_message(msg)
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = getenv('SMTP_HOST');
$mail->Port = 465;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->SMTPAuth = true;
$mail->Username = getenv('SMTP_USER');
$mail->Password = getenv('SMTP_PASS');
$mail->setFrom('[email protected]', 'SMTP Zen Bot');
$mail->addAddress('[email protected]');
$mail->Subject = 'Report ready';
$mail->Body = 'Your report is attached.';
$mail->send();
require 'net/smtp'
require 'mail'
mail = Mail.new do
from '[email protected]'
to '[email protected]'
subject 'Smoke tests passed'
body 'All checks green.'
end
smtp = Net::SMTP.new(ENV['SMTP_HOST'], 587)
smtp.enable_starttls
smtp.start('smtpzen.com', ENV['SMTP_USER'], ENV['SMTP_PASS'], :login) do |session|
session.send_message(mail.to_s, mail.from.first, mail.to)
end
package main
import (
"os"
"crypto/tls"
"log"
"net/smtp"
)
func main() {
host := os.Getenv("SMTP_HOST")
user := os.Getenv("SMTP_USER")
pass := os.Getenv("SMTP_PASS")
auth := smtp.PlainAuth("", user, pass, host)
msg := []byte("Subject: Ping\r\n\r\nEverything is running.\r\n")
conn, err := tls.Dial("tcp", host+":465", &tls.Config{ServerName: host})
if err != nil {
log.Fatal(err)
}
client, err := smtp.NewClient(conn, host)
if err != nil {
log.Fatal(err)
}
defer client.Close()
if err := client.Auth(auth); err != nil {
log.Fatal(err)
}
if err := client.Mail(user); err != nil {
log.Fatal(err)
}
if err := client.Rcpt("[email protected]"); err != nil {
log.Fatal(err)
}
w, err := client.Data()
if err != nil {
log.Fatal(err)
}
if _, err := w.Write(msg); err != nil {
log.Fatal(err)
}
w.Close()
client.Quit()
}
When testing locally, run the same examples inside a staging environment to confirm outbound ports are open. If the connection fails, switch between 465 and 587, or check that your firewall allows outgoing SMTP traffic.