in. NET (official version) environment sends an email
In the namespace of System.Web.mail in Microsoft .NET Environment, there are several classes that make you simply don't need to know a series of network protocols such as POP3, you can easily send emails in the program, very simple, This article briefly introduces how to implement it with a C # language.
First, we have to add this namespace.
Using system.web.mail;
Now let's generate the mail itself. Here is a named MailMessage class. The instance of this class is the mail object we have to send.
MailMessage Message = New MailMessage ();
Construct the message we want to send by setting the properties of the MESASGE object.
// sender address, is a string type
Message.from = "wanglei@e3soft.com";
// Recipient address, is a string type
Message.to = "wanglei@e3soft.com";
// CC's address is the string type
Message.cc = "wanglei@e3soft.com";
// Mail Theme, is a string type
Message.subject = "This is an example of testing";
// message content is a string type
Message.Body = "This is an example of test mail";
// mail type
Message.BodyFormat = mailformat.text; // Text Type
/ * You can also set it as a hypertext type as follows
Message.bodyFormat = mailformat.html; // hypertext type * /
/ / Set the priority of the 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 * / to this, the email we want to send is basically completed. Now, we need to use another class SMTPMail in this space to send this email.
Before using this class, we must first set an attribute. // Set the mail server, if not set, will send the mail server you systematically default mail server
// This is a static attribute, so it doesn't need to instantiate the class.
// This is also a string type
SMTPMAIL.SMTPSERVER = "192.9.200.5";
Now we can send this email.
//send email
// This is a static attribute, so it doesn't need to instantiate the class.
SMTPMAIL.SEND (Message);
If all, if you go smoothly, this email should have already sent it.