我想知道如何在重定向到另一个页面之前检查电子邮件是否已正确发送。因为如果它不快,它会在请求完成之前重定向..
while (reader.Read())
{
Fct.SendEmail("test.test.com", "test.test.com", "Maxime", userEmail, "email@myemail.com", "Access to our portal / Your password", body);
}
Response.Redirect("Logon.aspx");
这是我的功能发送电子邮件:
public void SendEmail(string smtpServer, string mailFrom, string mailFromDisplayName, string mailTo, string mailCc, string subject, string body)
{
try
{
using (SmtpClient client = new SmtpClient(smtpServer))
{
string to = mailTo != null ? string.Join(",", mailTo) : null;
string cc = mailCc != null ? string.Join(",", mailCc) : null;
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.From = new MailAddress(mailFrom, mailFromDisplayName);
mail.To.Add(to);
if (cc != null)
{
mail.Bcc.Add(cc);
}
mail.Subject = subject;
mail.Body = body.Replace(Environment.NewLine, "<BR>");
mail.IsBodyHtml = true;
client.Send(mail);
}
}
catch (Exception ex)
{ ex.ToString(); }
}