CDOSYS (CDO for Windows 2000)

Here's a code block for sending out an e-mail using CDOSYS.


    ' create the e-mail
    set o_msg = createobject("cdo.message")
    set o_conf = createobject("cdo.configuration")

    With o_conf.Fields
        .Item("http://schemas.microsoft.com
/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com
/cdo/configuration/smtpserver") = mailserver
        .Update
    End With

    With o_msg
        set .Configuration = o_conf
        .AutoGenerateTextBody = true
        .Fields("urn:schemas:httpmail:importance").Value = 2
        .Fields.Update()
        .To = emfaddress
        .From = emfemailfrom
        .Subject = emfemailsubject
        .HTMLBody = msg
        .AddAttachment "C:\files\a.doc"
        .Send
    End With

    set o_msg = nothing
    set o_conf = nothing

Notes

One of the things I find interesting is that some fields need to be set in the configuration object and others need to be set in the message object. It's certainly not clear as to which should be set where.

For setting importance, 2 = important, 1 = normal, and 0 = low.

Reference

Published April 21, 2004 · Updated September 17, 2005
Categorized as ASP
Short URL: https://snook.ca/s/155

Conversation

4 Comments · RSS feed
Avishai Shraga said on April 21, 2004

FYI: If you're running your App on an MS Exchange server and you want to use CDOSYS to send mail, you will need to change the IIS settings for that specific web site to run under the ExchangeApplicationPool. Otherwise you will get an "Access denied" error (like I did) and nothing you will try will fix it.

robin said on July 19, 2004

does this relate to using exchange as the cdo delivery mechanism. ie. sendusing = 1 and smtppickupaddress = exchanges one ?

Jonathan Snook said on July 19, 2004

By using the pickup folder (sendusing = 1), you're still using the SMTP protocol, even if it's the SMTP server that comes with Exchange. To send e-mail as a specific user on your exchange server, you'll want to look into CDO (not CDOSYS or CDONTS).

I hope that answers your question. :)

said on January 05, 2006

test

Sorry, comments are closed for this post. If you have any further questions or comments, feel free to send them to me directly.

Want to learn about scaling CSS for large projects?

I'm available for full and half-day workshops on scalable CSS architecture. I can provide on-site training for your team. Interested?
Get in touch.