This article explains the forwarding of emails with CDO and Exchange.
Using the code
CDO.DLL, responsible for CDO 1.2 (Collaboration Data Objects), is installed on the web server during the installation of Exchange 5.5 or Outlook for Web Applications (OWA).
Unlike CDONTS (Collaboration Data Objects for NT Server), CDO 1.x only works with the users who are authenticated on the Exchange Server.
In contrast to this, every user who has got the right to create ASP scripts can send emails via CDONTS.
Besides the access to the SMTP function of the exchange server, CDO 1.x offers access to further objects such as address book, calendar, dates, etc.
Therefore, the syntax for sending emails has slightly changed with regard to CDONTS. But this change is offset by the great amount of new possibilities.
The following conditions must be fulfilled:
- A mailbox must exist on the Exchange Server.
- CDO 1.x must be installed on the web server.
- The ASP script, which executes the mail code, must be run under the NT account of the mailbox owner.
- The information, under which rights which ASP scripts are executed, is recorded in the metabase of the web server. If the file name is changed, this information will not be updated in the metabase.
Therefore, it is recommended to create a separate subdirectory with the corresponding right.
The assignment of the right is done in “Properties”.
With the following ASP code, emails can be send with CDO 1.x via the Exchange Server:
In rows 1 and 2, the address of the Exchange Server as well as the alias of the mail account is defined. This information is combined to the user profile in row 4. In row 5, a MAPI session (Messaging Application Programming Interface) to the Exchange Server is created. With row 6, the user is registered. In rows 8 to 10, the subject and the text of the email are passed. Rows 12 to 14 pass the recipient and resolve an alias name into an email address. In row 16, the mail is sent. In rows 17 to 20, the session is closed and the objects are released.
1 Const cStrServer = "<name of exchange server>"
2 Const cStrMailbox = "<Mail-Account Alias>"
3 bstrProfileInfo = cStrServer & vbLf & cStrMailbox
5 Set objSess = Server.CreateObject("mapi.session")
6 objSess.Logon "", "", False, True, 0, True, bstrProfileInfo
8 Set objFBMess = objSess.Outbox.Messages.Add
9 objFBMess.Subject = "Test CDO-Mail"10 objFBMess.Text = "Content of the mail" mailtext
12 Set objRecips = objFjRecips = objFBMess.Recipients
13 objRecips.Add ("firstname.lastname@example.org")
19 Set objFBMess = nothing
20 Set objRecip = nothing
21 Set objSess = nothing
If the registration on the Exchange Server fails, the following error message appears:
Collaboration Data Objects error '000004f9'
The information store could not be opened. [MAPI 1.0 - [MAPI_E_LOGON_FAILED(80040111)]]
/wvs/_mailtest1.asp, row 13
In most cases, the error is due to the user’s authorization.