Prompt
How do I send an email when a user changes their address?
Latest observation
Sep 23, 2026
OpenAI APIWeb search: off
You can do this by detecting the address change in your backend and then triggering an email notification.
Common approach
1. Compare old vs. new address
When the user submits an update, check whether the address fields changed:
- street
- city
- state/province
- postal code
- country
If any of those changed, trigger an email.
2. Save the updated address
Update the user record in your database first, or in the same transaction if possible.
3. Send the email
Use an email service like:
- SendGrid
- Amazon SES
- Mailgun
- Postmark
- Nodemailer with SMTP
Example logic
Pseudocode
if (oldAddress !== newAddress) {
saveNewAddress();
sendEmail(user.email, "Your address was updated", "We noticed your address changed.");
}
Example in Node.js
const nodemailer = require("nodemailer");
async function updateAddress(userId, newAddress) {
const user = await db.users.findById(userId);
const oldAddress = user.address;
const addressChanged =
oldAddress.street !== newAddress.street ||
oldAddress.city !== newAddress.city ||
oldAddress.state !== newAddress.state ||
oldAddress.zip !== newAddress.zip ||
oldAddress.country !== newAddress.country;
if (addressChanged) {
await db.users.update(userId, { address: newAddress });
const transporter = nodemailer.createTransport({
host: "smtp.example.com",
port: 587,
auth: {
user: "smtp-user",
pass: "smtp-pass",
},
});
await transporter.sendMail({
from: "no-reply@yourapp.com",
to: user.email,
subject: "Your address has been updated",
text: "We noticed your address was changed in your account.",
});
}
}
Better practice
If you want this to happen reliably:
- use a database trigger or application event
- send the email asynchronously via a background job queue
- log the change for audit purposes
- avoid sending duplicate emails if the user updates the same address twice quickly
If you want, I can also show you:
- a version for Python/Django
- PHP/Laravel
- Ruby on Rails
- React + Node backend
- or a database trigger approach