hi,
i am sending async mail from asp dot net site, some time the mail sending work perfectly but some times it gives it shows below error
An asynchronous operation cannot be started at this time. Asynchronous operations may only be started within an asynchronous handler or module or during certain events in the Page lifecycle. If this exception occurred while executing a Page, ensure that the Page is marked <%@ Page Async="true" %>. This exception may also indicate an attempt to call an "async void" method, which is generally unsupported within ASP.NET request processing. Instead, the asynchronous method should return a Task, and the caller should await it.
here is my code
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient(SMTP.ToString());
mail.From = new MailAddress(EmailFrom.ToString());
//Email acpe = new Email();
mail.To.Add(Page.User.Identity.Name);
StreamReader reader = new StreamReader(Server.MapPath("~/some/somepage.html"));
string readFile = reader.ReadToEnd();
string myString = "";
myString = readFile;
//string name = HttpUtility.UrlEncode(Encrypt(Session["UserName"].ToString().Trim()));
//string technology = HttpUtility.UrlEncode(Encrypt(ddlTechnology.SelectedItem.Value));
myString = myString.Replace("{#URL}", "Label1.Text);
//myString = myString.Replace("{#lname}", TextBox2.Text);
//myString = myString.Replace("{#date}", DateTime.Now.ToString());
//myString = myString.Replace("{#message}", TextBox4.Text);
mail.Subject = "Welcome ";
mail.IsBodyHtml = true;
mail.Body = myString.ToString();
SmtpServer.Port = 25;
SmtpServer.Credentials = new System.Net.NetworkCredential(EmailFrom.ToString(), Password.ToString());
SmtpServer.EnableSsl = false;
object userState = mail;
SmtpServer.SendCompleted += new SendCompletedEventHandler(SMTPClientForAsy.SmtpClient_OnCompleted);
SmtpServer.SendAsync(mail, userState);