Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 30019

Sendmailasync waits for mail to be sent before moving to new page

$
0
0

I was using smptclien.Send(message) method for sending the final confirmation to user. But then I observed that it taking time and I learnt that I can use Sendmailasync method so that page will be redirected and the mail sending process will happen at server level. So I used the below code:

//Create the msg object to be sent        MailMessage msg = new MailMessage();        //Add your email address to the recipients        msg.To.Add("yyyyy@yyyy.com");        //Configure the address we are sending the mail from        MailAddress address = new MailAddress("xxxx@xxx.com");        msg.From = address;        msg.Subject = "anything";        msg.Body = "anything";        //Configure an SmtpClient to send the mail.        SmtpClient client = new SmtpClient();        client.DeliveryMethod = SmtpDeliveryMethod.Network;        client.EnableSsl = false;        client.Host = "relay-hosting.secureserver.net";        client.Port = 25;        //Setup credentials to login to our sender email address ("UserName", "Password")        NetworkCredential credentials = new NetworkCredential("xxxx@xxx.com", "xxxxxxxxxx");        client.UseDefaultCredentials = true;        client.Credentials = credentials;        //Send the msg        client.SendMailAsync(msg);        Response.Redirect("~/Partner/Signup.aspx");

But what I am seeing now is the last statement is waiting for client.SendMailAsync(msg); to complete then only it will redirect me to new page. My requirement is not to wait for the email to be send and if there is any error in mail sending then it is ok and skipped or just logged somewhere but it must not impact the processing speed and loading of new page. How can I achieve this. Please advice.


Viewing all articles
Browse latest Browse all 30019

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>