Im using the development server and the SmtpClient.SendAsync, the mail gets Sent, but it still blocks all other operations on the page until sending is complete. Ive searched alot and cant seem to see what the problem is
protected void SendMailButton_Click(object sender, EventArgs e) {
SendMailTemplate("verify@site.com", "your-email@gmail.com", "Your company Listing is Approved !", "CompanyApproved.txt", new string[] { "Send Mail company" });
}
public void SendMailTemplate(string From, string To, string Subject, string EmailTemplate, string[] Params) {
var message = new MailMessage(From, To);
message.IsBodyHtml = true;
message.Subject = Subject;
var sr = new StreamReader(HttpRuntime.AppDomainAppPath + "/Resources/EmailTemplates/" + EmailTemplate); //Cannot use Server.MapPath here
message.Body = sr.ReadToEnd(); sr.Close();
for (int i = 0; i < Params.Length; i++) {
message.Body = message.Body.Replace("<%Param" + (i + 1) + "%>", Params[i]);
}
var smtpClient = new SmtpClient("mail.site.com", 25);
smtpClient.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
smtpClient.SendCompleted += (s, e) => { smtpClient.Dispose(); message.Dispose(); };
smtpClient.SendAsync(message, null);
}