Prompt
How do I send mention notification emails?
Latest observation
Sep 23, 2026
OpenAI APIWeb search: off
To send mention notification emails, your app usually needs to do two things:
- Detect the mention in whatever content is being posted.
- Send an email to the mentioned user(s) when the post is saved.
A typical flow looks like this:
1) Detect mentions
When a user writes something like:
Hey @alice, can you review this?
Parse the text for @username patterns, then look up matching users in your database.
Example logic:
- Extract
alice - Find user record for
alice - Check whether the user has notifications enabled
2) Create a notification record
Before sending the email, it’s best to store a notification in your database so you can:
- prevent duplicates
- show in-app notifications
- retry email delivery if needed
Example fields:
- recipient_user_id
- actor_user_id
- post_id
- type:
mention - read_at
- created_at
3) Send the email
Use your email provider or mail library to send a notification email.
Email content usually includes:
- who mentioned them
- the post/comment content
- a link to view it
- an unsubscribe or notification settings link
Example subject:
You were mentioned by John
Example body:
John mentioned you in a comment:
"Hey @alice, can you review this?"
View it here: https://yourapp.com/posts/123
4) Do it asynchronously
Mention emails should usually be sent in a background job/queue rather than during the request, so posting stays fast.
Examples:
- Sidekiq / Celery / BullMQ / Delayed Job
- Cron worker or task queue
5) Avoid spam and duplicates
Best practices:
- Don’t email the same user multiple times for repeated mentions in one post
- Respect user notification preferences
- Rate limit emails
- Don’t send if the user mentioned themselves
- Consider batching if many mentions happen at once
Minimal implementation outline
Pseudocode
def create_post(author, content):
post = save_post(author, content)
usernames = extract_mentions(content)
for username in set(usernames):
user = find_user_by_username(username)
if user and user.wants_mention_emails:
create_notification(user, post, author)
queue_email(user.email, post, author)
return post
If you’re using a specific stack
I can give you exact code for:
- Ruby on Rails
- Django
- Node.js / Express
- Laravel
- ASP.NET
- React + backend
- SendGrid / Mailgun / SES / SMTP
If you want, tell me your stack and I’ll show a concrete example.