How to send email in C #

xiaoxiao2021-03-06  56

How to send email in C #

First, create an 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

be careful:

1. When sending a successful object Label3's text attribute shows "Send Success"

2. Object RegularExpressionValidator1 properties

ControlTovAlidate = "TextBox1"

ErrorMessage = "email format is wrong"

ValidationExpression = "/ w ([- .] / W ) * @ / w ([-.] / W ) * /. / W ([-.] / W ) *" // represents Email Verification format

When the address format of the recipient's email is incorrect, "email format is wrong"

3. Object TextBox1 Represents Recipient Address

Object TextBox2 represents title

Object TextBox2 representative send content

Second, display code (Webform1.aspx.cs)

1. Add code Using System.Web.mail in the file header;

2. Add Field Private System.Web.mail.mailMASSAGE M_MAIL;

3.

Private Void Page_Load (Object Sender, System.EventArgs E)

{

m_mail = new mailmessage (); // instantiate the 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";

}

This is achieved throughout the function, thank you for

转载请注明原文地址:https://www.9cbs.com/read-113974.html

New Post(0)