Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Simple CDO mailer: All these CDO constants wotsits needed?

Posted on 2007-10-16
4
Medium Priority
?
792 Views
Last Modified: 2008-01-09
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!
0
Comment
Question by:SatelliteCreative
  • 2
4 Comments
 
LVL 7

Assisted Solution

by:chisholmd
chisholmd earned 400 total points
ID: 20086603
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
 
LVL 4

Accepted Solution

by:
swinslow earned 600 total points
ID: 20086711
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
 
LVL 3

Author Comment

by:SatelliteCreative
ID: 20087079
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
 
LVL 3

Author Comment

by:SatelliteCreative
ID: 20092512
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

575 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question