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.