In the development of e-mail sender, we often need to use the corresponding components, in fact, do not need third-party components (for example: JMail) as usual can send email functions.
A file named Cdosys.dll can be found in the System32 subdirectory of the system directory (such as C:/winnt or c:/windows), and we can call this COM component via ASP to implement email delivery. CDOSYS is built on top of the SMTP protocol and the NNTP protocol and is installed as a component of Windows2000 server, and of course we can use Cdoex.dll in Exchange2000 to implement the mechanism for sending messages. Since Cdosys.dll is automatically embedded into the operating system, so there is no need to register the corresponding other sending programs, let us do a send instance.
1. Create a new project file
2, add the reference system directory under the Cdosys.dll file, in the reference will find added two to use the interface: CDO,ADODB
3, add a new item file sendmail.aspx, on its page placed three label, three TextBox, respectively, the role of the recipient address, subject, content, put a button buttons.
4. Switch to the code page and create the content
public void Cdosendmail ()
{
Try
{
Cdos. Message MSG = new CDO. Message ();
Msg.from = "[email protected]";
Msg.to = this. TextBox1.Text.Trim ();
Msg.subject = this. TextBox2.Text.Trim ();
Msg.HTMLBody = "+ "</body>Cdos. 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 Click event for button
private void Button1_Click (object sender, System.EventArgs e)
{
This. Cdosendmail ();
}
Run the program, and then check the mailbox.