Use CDO to send mail in ASP

Source: Internet
Author: User
Tags mail pack root directory

Use CDO to send mail in ASP

Sending mail in an ASP (Active Server Pages) is not a difficult task, and the requirement is to use the CDO component (collaborative Data Object), which is what NT Option Pack 4 installs. To confirm that the CDO component is properly installed on your machine, select Start/Control Panel/Add, remove program/nt option Pack 4 to see if the SMTP service is installed. If it is not installed, an error occurs when you run the code shown below (the error message is similar to "Invaild class string").

The code to create the CDO component instance in ASP is as follows:

〈 %

Dim OBJCDO

Set OBJCDO = Server.CreateObject ("CDONTS. NewMail ")

% 〉

Now you can send the mail! CDONTS. The NewMail instance has some obvious and simple properties and methods, and here's a look at the relevant code:

〈 %

' This code assumes the above CDO

' Instantiation code is included

objcdo.to = "mitchell@4guysfromrolla.com"

Objcdo.from = "gates@microsoft.com"

objcdo.cc = "barksdale@netscape.com,jobs@apple.com"

Dim Txtsubject

Txtsubject = "Hello scott! We were wanting your advice on some programming. Please come to Redmond at your earliest convenience for a very fat check! "

Objcdo.subject = "Attn:scott, we need you!!"

Objcdo.body = Txtsubject

Objcdo.send

% 〉

That's all it's all about. Several properties of a component are simple and practical. After executing the above code, a message will be sent from gates@microsoft.com to mitchelL@4guysfromrolla.comand CC to Barksdale@netscape.com and jobs@apple.com. The topic is a simple general information. Finally send the message using the Send method (do not forget to execute this method, otherwise the message will not be sent out).

Use CDO to send mail in ASP

The CDO component is quite powerful! You can use it to send attachments, write to mailing lists, and send schedules (as in Outlook).

Click this article to see how you can sell through private email. This article describes in detail the issue of better use of CDO components.

Here's a look at some of the other features of the CDO component, and the code snippet is as follows:

〈 %

objcdo.to = "someone@xyz.com (John Doe)"

Objcdo.from = "me@abc.com (Jane Doe)"

OBJCDO.BCC = "janedoe@aol.com" ' Blind cc

Objcdo.subject = "My Resume, per Request"

Objcdo.body = "Hello John." Here are a copy of my resume

Objcdo.importance = 2 ' High importance!

Objcdo.attachfile ("\\server\jane\resume.doc", "Resume.doc")

Objcdo.send ' Send off the email!

' Cleanup

Set Objcdo = Nothing

% >

Use CDO to send mail in ASP

As you can see, here are 2 new properties and a new method. The BCC attribute represents a secret send, which means that the person on the list of "to" receives the message and does not see the person who sent the message to the BCC. The importance property is also used, which has 3 options:

0-low

1-normal

2-high

If not specifically set, the default value for the Importance property is 1-normal. At the address, write the following style

"emailaddress@something.com (name)", where the name of the person who sent the message is indicated in parentheses. This way, John Doe, who receives the message, will see the message from Jane Doe, not me@abc.com.

The new method used here is attachfile. As the name of the method shows, it means attaching a file to the message you want to send. It takes 3 parameters, but only the first 2 are discussed here. The 1th parameter represents the file for the attachment, in this case the \\server\jane\resume.doc, the 2nd parameter is optional, the name of the attachment in the message, this is "Resume.doc", but you can choose to listen to some of the better names (for example, "Jane" s Nifty Resume ").

If you encounter an error denying access ...

Depending on the security settings on the Web server, you may encounter an error in the Reject method when you execute the Send method. When this error occurs, check to see if the Windows NT user IUSR_machinename has full control over the message root directory (typically located in C:\InetPub\mailroot\). (for example, the name of the Web server is Bob, then check if the user Iusr_bob has that permission).




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.