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 SMTP and NNTP protocols and installed as a component of Windows2000 Server. Of course, we can also use cdoex in exchange2000. DLL to implement the mail sending mechanism, because cdosys. DLL is embedded in the operating system, so you do not need to register the corresponding emails to send. Program For example, jmail.
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.