How to send Asynchronously Email

Recently need create a email system to arrow driver confirm a job from online. Every time the driver login to the web system, so they could accept a job, after the driver click accept button will send the email to be read by a software then update the database.

In that case, what will happen if multiple driver click the button at same time, then will cause my email problems.

Here is the simply solve by using Thread. you only need this code to solve you problems.

Thread email = new Thread(delegate()
            {
                var mysmtpClient = new SmtpClient();
                mysmtpClient.Send(acceptMessage);
            });
            email.IsBackground = true;
            email.Start();

//email sending process will be executed in background Thread and thus removes the latency involved in the email sending process.

Advertisements