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.