First add async= "true" to the header of the page
Introduced in the background code:
Using System.Net;
Using System.Net.Mail;
Using System.Text;
public void SendMail (string addrto, String mailbody)
{
String addrfrom = "****** @qq. com";//Mailbox ID
String Pwdfrom = "* * *";//Mailbox password
Setting SMTP Server information
SmtpClient smtpclient = new SmtpClient ();
Smtpclient.host = "smtp.qq.com";//Specify SMTP service name such as QQ mailbox for smtp.qq.com Sina cn mailbox for smtp.sina.cn, etc.
Smtpclient.port = 25; Specify port number
Create Server Authentication
NetworkCredential networkcredential_my = new NetworkCredential (Addrfrom, Pwdfrom);
Instantiate sender Address
MailAddress mailaddress_from = new MailAddress (Addrfrom, "*******");
Specify sender information including email address and mailbox password
Smtpclient.credentials = new NetworkCredential (mailaddress_from. Address, Pwdfrom);
MailAddress mailaddress_to = new MailAddress (Addrto);
MailMessage mailmsg = new MailMessage (Mailaddress_from, mailaddress_to);
MailMsg. To.clear (); Clear history send messages to prevent recipients from receiving error messages when they are sent (the list of recipients repeats repeatedly)
MailMsg. From = mailaddress_from;//Sender mailbox
MailMsg. To.add (mailaddress_to);//Add Recipient email Address
Message subject
MailMsg. Subject = "password";
MailMsg. subjectencoding = Encoding.UTF8;
Message body
MailMsg. Body = Mailbody;
MailMsg. bodyencoding = Encoding.UTF8;
smtpclient.sendcompleted + = new Sendcompletedeventhandler (smtpclient_sendcompleted);//processing events after the mail is sent
Object userState = MailMsg;
Smtpclient.sendasync (MailMsg, userState);
}
public void smtpclient_sendcompleted (object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
ShowMessage ("Sent successfully! ");
Confirmbttn.enabled = true;
Try
{
if (e.cancelled)
{
ShowMessage ("Send Cancel");
}
if (E.error = = null)
{
ShowMessage ("Password has been sent to your registered email");
}
Else
{
ShowMessage ("Send failed" + e.error.message);
}
}
Catch
{
}
throw new NotImplementedException ();
}
. NET Sending mail