Qq mail verification code and email Verification Code
Sometimes the memory of a person is the same as that of a fish. It takes only seven seconds and a short time!
. NET Web form implementation forgot password, use QQ mailbox verification to modify
1. First, set the email address for sending an individual or enterprise email.
2. Set the logon email address,
3. Disable email
4. Start to write code...
1. A simple front-end design
2. The background first references the namespace
Using System. Net;
Using System. Net. Mail;
/// <Summary>
/// Send the verification code
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "e"> </param>
Protected void button#click (object sender, EventArgs e)
{
// Message sent
This. Label1.Text = "* The verification code has been sent to your mailbox. Check it carefully! ";
// Generate a random Verification Code
Int num;
String str = string. Empty;
Random rm = new Random ();
For (int I = 0; I <6; I ++)
{
Num = Convert. ToInt32 (rm. NextDouble () * 10 );
Str + = num;
}
Session ["Rom"] = str;
String content = "*** technology reminds you that you are using the account security verification service. Your verification code for this operation is:" + str;
// Recipient's email address, email title, and email content
SendEmail1 ("xxx@qq.com", "[Xiaozhang technology] background login modify user information prompt", content );
}
/// <Summary>
/// Send the email Verification Code
/// </Summary>
/// <Param name = "mailTo"> recipient </param>
/// <Param name = "mailSubject"> title </param>
/// <Param name = "mailContent"> content </param>
///
Public static void SendEmail1 (string mailTo, string mailSubject, string mailContent)
{
SmtpClient mailClient = new SmtpClient ("smtp.qq.com ");
MailClient. EnableSsl = true;
MailClient. usedefacrecredentials = false;
// Credentials logs on to the SMTP server for authentication.
MailClient. Credentials = new NetworkCredential ("xxx@qq.com", "suzgotcsfwbpbbec"); // mailbox,
MailMessage message = new MailMessage (new MailAddress ("xxx@qq.com"), new MailAddress (mailTo); // sender, recipient
Message. IsBodyHtml = true;
Message. Body = mailContent; // mail content
Message. Subject = mailSubject; // mail Subject
MailClient. Send (message); // Send an email
}
/// <Summary>
/// Log on
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "e"> </param>
Protected void Button2_Click (object sender, EventArgs e)
{
If (TextBox1.Text. Trim () = Session ["Rom"]. ToString ())
{
Response. Write ("<script> alert (\" Verification Successful! \ "); </Script> ");
This. Label1.Text = "";
}
Else
{
Response. Write ("<script> alert (\" Verification Failed! \ "); </Script> ");
This. Label1.Text = "* Incorrect verification code. Enter again! ";
}
}
This is the end and you can run it.Welcome to join us!