Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8319933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:29:04+00:00 2026-06-08T22:29:04+00:00

When a user signs up on my website I create a user record in

  • 0

When a user signs up on my website I create a user record in the database with email_sent = ‘NO’. I then have a cron job that sends welcome emails every few minutes. It selects all user records where email_sent = ‘NO’ and sends the welcome email.

If the email is sent successfully it then updates the user record to email_sent=’YES’. My question is, how can I avoid the scenario where the email sends successfully but the update of the user record fails and the next time the cron job runs it sends a duplicate email. Even if I used a database transaction and I updated the record before sending the email but committed afterwards, if the commit fails I would have the same situation with duplicate emails being sent.

The alternative is to update the record to email_sent=’YES’ and commit immediately, and then attempt to send the email. But if the email send fails then no email is sent.

Is there any way to guarantee exactly once sending of an email? I realize the email delivery could ultimately fail due to a number of external factors, but I just want to ensure that my SMTP server successfully shoves it off exactly once.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:29:05+00:00Added an answer on June 8, 2026 at 10:29 pm

    Your comment states that the commits aren’t failing so you may be worrying about the wind.

    Keep the transaction as small as possible and have it fail whichever way is more acceptable in your system…

    BeginTransaction;
    LookupRecord;
    
    SendMail;
    
    if(SentSuccessfully)
    {
        UpdateRecord(Sent=True);
        CommitTransaction;
    }
    else
    {
        RollbackTransaction;
    }
    

    Alternatively you could do it with more complexity and without the transaction around the email function, but I don’t see this as better:

    BeginTransaction;
    LookupRecord;
    UpdateRecord(Sent=True);
    CommitTransaction;
    
    SendMail;
    
    if(!SentSuccessfully)
    {
        UpdateRecord(Sent=False);
    }
    

    Either way, if you have errors and the correct value is not committed to the database, there isn’t much you can do to avoid it without introducing (potentially unnecessary) complexity. You really should focus on making the update & transaction rock-solid so it doesn’t fail to update.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a website with ASP.NET MVC3. When a user signs in, I pull
I am creating a service that allows my website visitors to create content (text)
I'm designing a database that will be the backend for a marketplace website. There
Is it possible to have a website where each user gets their own URL
I have a website that is using SMF forum (simplemachines.org). I have been using
I'm currently trying to create user authorization that follows: The definitive guide to form-based
i have create Facebook app for my external website and i created an Access
i build a website and it has a sign in form, when user sign
When a user signs up on my site I want to be able to
Each time my user signs in, we pull his profile picture from Facebook. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.