In NET (official version) environment Send mail

Source: Internet
Author: User
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= "wanglei@e3soft.com";

Recipient address, is a string type

Message.to= "wanglei@e3soft.com";

The address of the CC message, which is the string type

Message.cc= "wanglei@e3soft.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= "192.9.200.5";


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.



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.