C # Two Methods for sending emails in. net1.1 and. net2.0

Source: Internet
Author: User
Tags mailmessage smtpclient

. Net1.1
Using system. Web. mail;
Usage:
Sendsmtpemail ("100.100.100.100", "someone@xxx.com", "XXXX", "someone@xxx.com", "webtest", textbox1.text, null, null );
Method body:
Public void sendsmtpemail (string strsmtpserver, string strfrom, string strfrompass, string strto, string strsubject, string strbody, string BCC, string CC)
{
System. Web. Mail. mailmessage mail = new system. Web. Mail. mailmessage ();
Mail. bodyformat = mailformat. html;
Mail. From = strfrom;
Mail. To = strto; // separate multiple recipients with semicolons
Mail. bcc = BCC;
Mail. Cc = cc;
Mail. Subject = "mail test !!! ";
Mail. Body = textbox1.text;
Mail. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1 ");
Mail. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/sendusername", strfrom );
Mail. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/sendpassword", strfrompass );

System. Web. Mail. mailattachment attachment = new system. Web. Mail. mailattachment ("C: \ log. log ");
Mail. attachments. Add (Attachment );
Smtpmail. smtpserver = strsmtpserver;
Smtpmail. Send (Mail );
}
. Net2.0
Using system. net. mail;
Usage:
Sendsmtpemail ("100.100.100.100", "someone@xxx.com", "XXXX", "someone@xxx.com", "webtest", textbox1.text, null, null );
Method body:
Public 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 system. net. Mail. mailmessage (strfrom, strto, strsubject, strbody );
System. net. Mail. Attachment attachment = new system. net. Mail. Attachment ("C: \ log. log ");
Message. attachments. Add (Attachment );
Message. bodyencoding = system. Text. encoding. utf8;
Message. isbodyhtml = true;
Client. Send (Message );
}

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.