views:

87

answers:

2

I have some ASP code that I've "inherited" from my predecessor (no, it's not an option to update it at this time...It would take an act of not only Congress, but every other foreign country too) and I'm having an issue sending mail on one of the pages. It is an almost identical code snippet from the other page, but this one throws an error when I try to 'Send'.

Code below:

Set myMail=CreateObject("CDO.Message")
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2

'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="localhost"

'Server port
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25 
myMail.Configuration.Fields.Update

myMail.Subject="Subject"
myMail.From=from_email
myMail.To=email
myMail.TextBody= "Body Text of message"
myMail.Send

The error thrown is: Error Type: (0x8004020F) The event class for this subscription is in an invalid partition

I'd appreciate any and all help!!!

Thanks! JFV

+1  A: 

This seems to be an issue with the smtp server...

have a look at http://forums.aspfree.com/asp-development-5/the-event-class-for-this-subscription-is-in-an-invalid-103189.html

and also

http://www.powerasp.com/info/4558~General~info.htm

Gaby
+2  A: 

I had similar issues trying to get CDO to work. I found a really cool article on this website Why does CDO.Message give me 8004020F errors?

Here is the code I finally got to work. I could never get localhost to work as the SMTP Server. Find out what the name of the mail server is and make sure to use that name.

<!--METADATA TYPE="typelib" UUID="CD000000-8B95-11D1-82DB-00C04FB1625D" NAME="CDO for Windows 2000 Type Library" -->
<!--METADATA TYPE="typelib" UUID="00000205-0000-0010-8000-00AA006D2EA4" NAME="ADODB Type Library" -->
<%
Set cdoConfig = CreateObject("CDO.Configuration")

With cdoConfig.Fields
        .Item(cdoSendUsingMethod) = cdoSendUsingPort
        .Item(cdoSMTPServer) = "nameofmailservergoeshere"
        .Update
End With


Set cdoMessage = CreateObject("CDO.Message")

With cdoMessage
        Set .Configuration = cdoConfig
        .From = "[email protected]"
        .To = "[email protected]"
        .Subject = "Sample CDO Message"
        .TextBody = "This is a a test message using CDO."
        .Send
End With

Set cdoMessage = Nothing
Set cdoConfig = Nothing
%>

Cape Cod Gunny
I'll check it out tomorrow when I get back in the office. Thanks for the info. I'll let you know how it goes.
JFV
@JFV: The problem with your code is that it is modifing an existing configuration object which would be initialised from IIS config. The code in this answer is creating a fresh instance of a configuration object and replacing the default configuration. Other than that this code does exactly the same as your code but utalises the type library declarations. The reference to the ADO library is not necessary in this case.
AnthonyWJones
@Cape Cod Gunny: Worked like a charm! I appreciate all the help!
JFV