In. net Framework 1.x we need to use system. web. the class in the mail namespace to send emails, but the function is relatively weak. For example, your email server needs to verify before sending emails. in NET 1.1, the followingCodeFor additional configuration.
Mail. Fields. Add ( " Http://schemas.microsoft.com/cdo/configuration/smtpauthenticate "
, " 1 " );
Mail. Fields. Add ( " Http://schemas.microsoft.com/cdo/configuration/sendusername "
, " My_username_here " );
Mail. Fields. Add ( " Http://schemas.microsoft.com/cdo/configuration/sendpassword "
, " Super_secret " );
For how to send emails under. Net 1.x, see:
Http://blog.joycode.com/joy/archive/2004/01/14/11405.aspx
In. NET Framework 2.0, the system. net. Mail namespace provides support for mail operations, which is more powerful. For example, if your email server needs verification before sending the email, 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. usedefacrecredentials = false;
Client. Credentials = new system. net. networkcredential (strfrom, strfrompass );
Client. deliverymethod = smtpdeliverymethod. Network;
System. net. Mail. mailmessage message = new mailmessage (strfrom, strto, strsubject, strbody );
Message. bodyencoding = system. Text. encoding. utf8;
Message. isbodyhtml = true;
Client. Send (Message );
}
You can modify attributes such as usedefaultcredentials credentials deliverymethod to easily support sending emails in various situations.