. NET send email (Verification Code),. net send email Verification Code
First look at the front-end:
Set before writing code:
I. log on to the QQ mailbox and click Settings.
II:
III:
// Start typing the code below...
// Two namespaces
// Using System. Net;
// Using System. Net. Mail;
/// <Summary>
/// Send verification code button
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "e"> </param>
Protected void button#click (object sender, EventArgs e)
{
// Random verification code
Random rm = new Random ();
Int I;
String str = string. Empty;
For (int p = 0; p <6; p ++)
{
I = Convert. ToInt32 (rm. NextDouble () * 10 );
Str + = I;
}
String content = "** technology reminds you that you are using the go-through email security verification service. Your verification code for this operation is:" + str
SendEmail1 ("1208240949@qq.com", "[** technology] background login modify user information prompt", content); // recipient's mailbox, mailbox title, mailbox content
}
# Region
/// <Summary>
/// Send email
/// </Summary>
/// <Param name = "mailTo"> recipient </param>
/// <Param name = "mailSubject"> title </param>
/// <Param name = "mailContent"> content </param>
/// <Returns> </returns>
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 ("1208240907@qq.com", "aaaaaaaaaaaa"); // mailbox,
MailMessage message = new MailMessage (new MailAddress ("1208240907@qq.com"), new MailAddress (mailTo); // sender, recipient
Message. IsBodyHtml = true;
// Message. Bcc. Add (new MailAddress ("tst@qq.com"); // you can Add multiple recipients.
Message. Body = mailContent; // mail content
Message. Subject = mailSubject; // mail Subject
// Attachment
// Attachment att = new Attachment (@ "C:/hello.txt ");
// Message. Attachments. Add (att); // Add an attachment
// Console. WriteLine ("Start Send Mail ....");
// Send ....
MailClient. Send (message); // Send an email
}
# Endregion
/// <Summary>
/// Verification code button
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "e"> </param>
Protected void Button2_Click (object sender, EventArgs e)
{
If (TextBox1.Text. Trim () = Session ["Rom"]. ToString ())
{
Page. ClientScript. RegisterClientScriptBlock (Page. ClientScript. GetType (), "myscripts", "<script> alert (\" Verification Successful! \ "); </Script> ");
}
Else
{
Page. ClientScript. RegisterClientScriptBlock (Page. ClientScript. GetType (), "myscripts", "<script> alert (\" Verification Failed! \ "); </Script> ");
}
}
Then run