Asp. NET combine COM components to send email

Source: Internet
Author: User
Tags config mail reference trim
asp.net can find a file named Cdosys.dll in the System32 subdirectory of the system directory (such as C:\Winnt or C:\Windows), and we can call this COM component through ASP.net to send the email. CDOSYS is built on top of the SMTP protocol and NNTP protocol and is installed as a component of Windows2000 server. Of course, we can also use Exchange2000 Cdoex.dll to implement the mechanism of sending mail, because Cdosys.dll embedded into the operating system, so no longer to register the corresponding other mail-sending programs such as JMail.

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, put three labels on its page, three textbox, the role is the recipient address, subject, content, place a button buttons.

4, switch to the code page, create content

public void Cdosendmail ()
{
Try
{
Cdos. Message MSG = new CDO. Message ();
Msg.from = "Rattlesnake@263.net";
Msg.to = this. TextBox1.Text.Trim ();
Msg.subject = this. TextBox2.Text.Trim ();
Msg.HTMLBody = "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 ();
}

You can run the program.




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.