. NET send email (Verification Code),. net send email Verification Code

Source: Internet
Author: User
Tags mailmessage net send smtpclient

. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.