web| Send mail
at Microsoft. NET environment in the System.Web.Mail namespace, provides a number of classes, so that you do not need to understand POP3, such as a series of network protocols, you can easily in the program to send mail, very simple, this article on a brief introduction, how to use the C # language to achieve.
First, we're going to add this namespace
Using System.Web.Mail;
Now we're going to generate the message itself. A class named MailMessage is provided here. An example of this class is the message object that we want to send.
MailMessage message=new MailMessage ();
Construct the message that we want to send by setting the properties of the Mesasge object.
The sender address, which is a string type
Message.from= "Test1@test.net";
Recipient address, is a string type
Message.to= "test2@test.com";
The address of the CC message, which is the string type
Message.cc= "test3@test.com";
Message subject, is a string type
Message.subject= "This is an example of a test";
Message content, is a string type
Message.body= "This is an example of a test email";
Message type
Message.bodyformat=mailformat.text; Text type
/* You can also set the following as a hypertext type
message.bodyformat=mailformat.html; Hypertext Type * *
Set the priority of a message
message.priority=mailpriority.low;//Low-priority
/* can also be set as follows
Message.priority=mailpriority.normal; General priority
Message.priority=mailpriority.high; High-Priority * *
At this point, the message we want to send is basically constructed.
Now, we need to use another class smtpmail in this space to send this message.
Before using this class, we first set a property of it.
Set up the mail server, if not set will be your system default mail server to send
This is a static (static) property, so you do not need to instantiate the class
This is also a string type
Smtpmail.smtpserver= "mail.domainname.com";
Now, we can send this email.
Send mail
This is a static (static) property, so you do not need to instantiate the class
Smtpmail.send (message);
If all goes well, this email should have been sent out. The email address, server address, etc. listed in this example are virtual, and you can change the test to what you need.