Simple CDO mailer: All these CDO constants wotsits needed?

Hi, I'm just writing a small ASP script to mail errors to an admin if there are ASP errors using CDO.Message.
I need to specify an SMTP server address and user/pass. I've found plenty of examples, but most of them are HUGE! Is it really neccessary to include ALL these constants as in the example below?

I don't know what these cosntants are for and what they have to do with 'schemas'. Sorry this is probably some simple MS thing that I - as a PHP dev - don't understand.

Example:

Const cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSendUsingPort = 2
Const cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort = "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Const cdoSMTPConnectionTimeout = "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
Const cdoSMTPAuthenticate = "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
Const cdoBasic = 1
Const cdoSendUserName = "http://schemas.microsoft.com/cdo/configuration/sendusername"
Const cdoSendPassword = "http://schemas.microsoft.com/cdo/configuration/sendpassword"
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields
With Fields
      .Item(cdoSendUsingMethod)       = cdoSendUsingPort
      .Item(cdoSMTPServer)            = "my.server.com"
      .Item(cdoSMTPServerPort)        = 25
      .Item(cdoSMTPConnectionTimeout) = 10
      .Item(cdoSMTPAuthenticate)      = cdoBasic
      .Item(cdoSendUserName)          = "username"
      .Item(cdoSendPassword)          = "password"
      .Update
End With

Set objMessage = Server.CreateObject("CDO.Message")
Set objMessage.Configuration = objConfig

With objMessage
      .To       = "toaddress"
      .From     = "fromaddress"
      .Subject  = "subject"
      .HTMLBody = "<b>overkill for a simple mailer?</b>"
      .Send
End With

Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing



So yea... that seems like overkill to me, is it all really neccesary?
Cheers!
LVL 3
SatelliteCreativeAsked:
Who is Participating?
 
swinslowCommented:
It's too bad you need to specify a mail server and authenticate with it, otherwise it is much simpler not to:

Set ObjNM=CreateObject("CDO.Message")
ObjNM.Subject = "Your Subject Line"
ObjNM.From = "Me@here.com"
ObjNM.To = "You@There.com"
ObjNM.HTMLBody = "Your Message Goes Here"
ObjNM.Send
Set ObjNM = Nothing

However, since you do need to authenticate and specify a mail server it still is not as complicated as your code shows, just a couple extra lines:

Set ObjNM=CreateObject("CDO.Message")
ObjNM.Subject = "Your Subject Line"
ObjNM.From = "Me@here.com"
ObjNM.To = "You@There.com"
ObjNM.HTMLBody = "Your Message Goes Here"
ObjNM.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.your.com"
ObjNM.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "youruserid"
ObjNM.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword"
ObjNM.Configuration.Fields.Update
ObjNM.Send
Set ObjNM = Nothing
0
 
chisholmdCommented:
Yes I think it is.  I agree the CDO stuff is always really verbose.  other COM based mailers are much more compact.   Part of the reason I think that cdo is so verbose is that it is a foundational library for OUtlook & exchange etc.

0
 
SatelliteCreativeAuthor Commented:
Thanks both, and thanks for example swinslow, I had to add the 'sendusing' config to get it working so for the benefit of anyone else stumbling across this post in the future, this what I've ended up with:

Set objMessage = Server.CreateObject("CDO.Message")
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.server.com"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "user"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "pass"
objMessage.Configuration.Fields.Update
objMessage.To = "to@something.net"
objMessage.From = "from@something.net"
objMessage.Subject = "my subject"
objMessage.HTMLBody = "<b>this works</b>"
objMessage.Send
0
 
SatelliteCreativeAuthor Commented:
Hi.. again just for the benefit of future 'viewers', my code block above only works for 'local' mail on some set-ups, and when sending to an external address on a server that doesn't like relaying for un-authenticated users (so thats ALL of them right?) you'll probably get a '553' smtp error.

To avoid this add the following somewhere in the config lines:

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.