Prompt
How do I send an email when something happens in my app?
Latest observation
Sep 23, 2026
OpenAI APIWeb search: off
The usual approach is:
-
Detect the event in your app
Example: user signs up, order is placed, password reset is requested. -
Trigger a backend action
Don’t send email directly from the frontend. Call your server or a background job. -
Use an email service/provider
Common options:- SendGrid
- Mailgun
- Amazon SES
- Postmark
- Resend
-
Send the email from the backend Your backend prepares the recipient, subject, and body, then calls the email provider’s API.
-
Do it asynchronously if possible For reliability, queue the email in a background worker so the app doesn’t wait on the send.
Example flow
- User places an order
- Your app writes the order to the database
- Your backend emits an
order_createdevent - A worker listens for that event
- Worker sends an email confirmation
Very small example in Node.js
import nodemailer from "nodemailer";
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS,
},
});
await transporter.sendMail({
from: "yourapp@example.com",
to: "user@example.com",
subject: "Welcome!",
text: "Thanks for signing up.",
});
Important notes
- Use environment variables for credentials.
- Add rate limiting / retries.
- Consider HTML templates for better-looking emails.
- Make sure your provider is configured for SPF/DKIM/DMARC to improve deliverability.
If you want, I can show you:
- how to do this in Python / Node / PHP / Ruby
- how to set it up with SendGrid / SES / Resend
- how to trigger emails from a database event or webhook