How mail is sent under. NET 2.0

Source: Internet
Author: User
Tags mail how to send mail smtpclient
Send mail

In the. NET Framework 1.x we need to use classes under the System.Web.Mail namespace to send mail, but the function is weak, such as your mail server needs to verify to send mail, in. NET 1.1, you need to use the following code for additional configuration.

Mail. Fields.Add ("Http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"

Mail. Fields.Add ("Http://schemas.microsoft.com/cdo/configuration/sendusername"

Mail. Fields.Add ("Http://schemas.microsoft.com/cdo/configuration/sendpassword"

How to send mail under. NET 1.x please refer to:
Http://blog.joycode.com/joy/archive/2004/01/14/11405.aspx

Under the. Net Framework 2.0, support for mail operations is provided in the System.Net.Mail namespace, and his capabilities are more powerful. For example, your mail server needs to verify to send mail, the code is simply as follows:

public static void Sendsmtpemail (String strsmtpserver, String strfrom,
String Strfrompass, String Strto, String strsubject, String strbody) ... { System.Net.Mail.SmtpClient client = new SmtpClient (strsmtpserver); Client. useDefaultCredentials = false;
New System.Net.NetworkCredential (Strfrom, strfrompass); Client. Deliverymethod = Smtpdeliverymethod.network;
New MailMessage (Strfrom, Strto, Strsubject, strbody); Message. bodyencoding = System.Text.Encoding.UTF8; Message. Isbodyhtml = true; Client. Send (message);

We can easily support the way in which messages are sent in various situations by modifying attributes such as useDefaultCredentials Credentials Deliverymethod.



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.