Prompt
How do I use SMTP relay for transactional email?
Latest observation
Oct 10, 2026
OpenAI APIWeb search: off
Using an SMTP relay for transactional email usually means your app sends email to a trusted relay service, and that service delivers it to recipients. This is common for password resets, order confirmations, receipts, alerts, and other automated messages.
1) What SMTP relay is
Instead of your app sending mail directly to the recipient’s mail server, it sends to an SMTP server such as:
- Amazon SES
- SendGrid
- Mailgun
- Postmark
- Microsoft 365 / Google Workspace SMTP relay
- A private/company mail relay
The relay handles:
- delivery
- IP reputation
- bounce handling
- authentication
- retries
2) Basic setup steps
A. Pick a relay provider
Choose based on:
- deliverability
- pricing
- API vs SMTP support
- domain authentication features
- bounce/webhook support
B. Verify your sending domain
Usually requires DNS records:
- SPF: authorizes the relay to send for your domain
- DKIM: signs messages cryptographically
- DMARC: tells receivers how to treat unauthenticated mail
C. Create SMTP credentials
You’ll get:
- SMTP host
- port
- username
- password or API-based SMTP password
Common ports:
- 587: STARTTLS, most common
- 465: implicit TLS
- 25: often blocked or restricted
D. Configure your app
Set:
- SMTP host
- port
- encryption/TLS
- username/password
- sender/from address
E. Send test mail and verify headers
Check:
- message lands in inbox
- SPF/DKIM/DMARC pass
- headers show correct sender
- bounces are tracked
3) Example SMTP settings
Typical configuration:
SMTP_HOST=smtp.your-relay.com
SMTP_PORT=587
SMTP_USERNAME=your-username
SMTP_PASSWORD=your-password
SMTP_FROM=no-reply@yourdomain.com
SMTP_TLS=true
4) Example in code
Node.js (Nodemailer)
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: 587,
secure: false, // true for 465
auth: {
user: process.env.SMTP_USERNAME,
pass: process.env.SMTP_PASSWORD,
},
});
async function sendReceipt(to) {
await transporter.sendMail({
from: 'My App <no-reply@yourdomain.com>',
to,
subject: 'Your receipt',
text: 'Thanks for your order.',
html: '<p>Thanks for your order.</p>',
});
}
Python (smtplib)
import smtplib
from email.message import EmailMessage
msg = EmailMessage()
msg["Subject"] = "Your receipt"
msg["From"] = "My App <no-reply@yourdomain.com>"
msg["To"] = "user@example.com"
msg.set_content("Thanks for your order.")
with smtplib.SMTP("smtp.your-relay.com", 587) as server:
server.starttls()
server.login("SMTP_USERNAME", "SMTP_PASSWORD")
server.send_message(msg)
5) Best practices for transactional email
- Use a dedicated sender like
no-reply@orsupport@ - Authenticate your domain with SPF/DKIM/DMARC
- Keep transactional and marketing mail separate
- Use a descriptive subject line
- Include plaintext and HTML versions
- Handle bounces and complaints
- Don’t send bulk mail through the transactional relay unless allowed
- Rate limit and retry on temporary failures
- Monitor delivery logs
6) Common mistakes
- Using an unverified “From” address
- Forgetting TLS
- Hardcoding credentials in code
- Sending from the wrong domain
- Ignoring SPF/DKIM/DMARC
- Not processing bounce messages
- Using SMTP relay for high-volume marketing mail
7) If you need relay through your own mail server
If you’re using something like Postfix as a relay:
- configure authenticated relay access
- restrict who can send through it
- set up SPF/DKIM on your domain
- ensure your outbound IP has good reputation
- monitor logs for abuse
If you want, I can give you:
- a provider-specific setup guide (SES, SendGrid, Mailgun, Postmark, Gmail/Google Workspace, Microsoft 365), or
- a ready-to-use SMTP config for your language/framework.