How to send email in C #

Source: Internet
Author: User
Tags mail mailmessage
First, create the interface (WebForm1.aspx)



Type
Object Name
Text Property

Label
Label1
Recipient Address:

Label
Label2
Title:

Label
Label3


Textbox
TextBox1


Textbox
TextBox2


Textbox
TextBox3


Button
Button1
Send

RegularExpressionValidator
RegularExpressionValidator1









Note the point:

1. When the Send Success object Label3 's Text property shows "Send Success"

2. Properties of Object RegularExpressionValidator1

Controltovalidate= "TextBox1"

errormessage= "email format is wrong"

Validationexpression= "\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) * "//on behalf of email verification format

When the recipient's email address format is not correct will show "email format is wrong"

3. Object TextBox1 represents the recipient address

Object TextBox2 represents a title

Object TextBox2 on behalf of the sending content



Second, display code (WebForm1.aspx.cs)



1. Add code using System.Web.Mail to the head of the file;

2. Add field private System.Web.Mail.MailMessage m_mail;

3.

private void Page_Load (object sender, System.EventArgs e)

{

M_mail=new MailMessage (); Instantiating a MailMessage object

}

4. Double-click the Send button

private void Button1_Click (object sender, System.EventArgs e)

{

M_mail.from= "jinq@gpssz.com";

M_mail.to=textbox1.text;

M_mail.subject=textbox2.text;

m_mail.bodyformat=mailformat.html;

M_mail.body=textbox3.text;

Smtpmail.send (M_mail);

label3.text= "Send Success";

}



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.