ASP. NET combined with COM component to send email hbzxf (original)

Source: Internet
Author: User

ASP. NET sends email with COM Component
Zhang Feng (A Hao. Net)

Send the email in the development emailProgramWe often need to use the corresponding components. In fact, third-party components (such as jmail) are not required to send emails as usual.

In the System32 subdirectory of the system directory (such as c: \ WINNT or C: \ Windows), you can find a name named cdosys. DLL file, we can use ASP. net calls this COM component to send emails. Cdosys is built on the SMTP and NNTP protocols and installed as a component of the Windows2000 Server. Of course, we can also use cdoex. dll in exchange2000 to implement the mail sending mechanism. Because cdosys. dll is automatically embedded in the operating system, you do not need to register other sending programs. Let's create a sending instance.

1. Create a project file

2. Add the cdosys. dll file under the reference system directory. You will find two interfaces to be used: CDO and ADODB.

3. Add the new project file sendmail. aspx, and place three labels and three textbox on the page to apply the recipient address, topic, and content respectively, and place a button.

4. SwitchCodePage to create the content

Public void cdosendmail ()
{
Try
{
CDO. Message MSG = new CDO. Message ();
MSG. From = "rattlesnake@263.net ";
MSG. To = This. textbox1.text. Trim ();
MSG. Subject = This. textbox2.text. Trim ();
MSG. htmlbody = "<HTML> <body>" + this. textbox3.text
+ "</Body> CDO. iconfiguration Config = msg. configuration;
ADODB. Fields ofields = config. fields;
Ofields ["http://schemas.microsoft.com/cdo/configuration/sendusing"]. value = 2;
Ofields ["http://schemas.microsoft.com/cdo/configuration/sendusername"]. value = "Rattlesnake ";
Ofields ["http://schemas.microsoft.com/cdo/configuration/sendpassword"]. value = "pass ";
Ofields ["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"]. value = 1;
Ofields ["http://schemas.microsoft.com/cdo/configuration/languagecode"]. value = 0x0804;
Ofields ["http://schemas.microsoft.com/cdo/configuration/smtpserver"]. value = "smtp.263.net ";
Ofields. Update ();

MSG. bodypart. charset = "gb2312 ";
MSG. htmlbodypart. charset = "gb2312 ";

MSG. Send ();
MSG = NULL;
}
Catch (exception ERR)
{
Throw err;
}
}

5. Add a click event for the button

Private void button#click (Object sender, system. eventargs E)
{
This. cdosendmail ();
}

Run the program and check the mailbox.

Related Article

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.