Link to home
Create AccountLog in
Avatar of dpd3891
dpd3891Flag for United States of America

asked on

CDO (Error: property item is read): sending email using SMTP Server

Hi

I want send email message using SMTP server

I am trying to use https://www.experts-exchange.com/questions/20902572/CDO-works-one-place-not-the-other.html code
I am using CDO as I have username and password for smtp server (I also tried to use MailMessage  object  using next link: http://www.microsoft.com/mspress/books/sampchap/6436a.aspx, but my requirement is to use username and password to access smtp server)

Now when I try to use below code with my SMTP server, port, username, password.etc
I got error saying "property item is read" for .Item()........all parameters. (FYI: I am using vb.net 2008)


Const cdoSMTPAuthenticate = "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
Const cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing
 
 Const cdoSendusername = "http://schemas.microsoft.com/cdo/configuration/sendusername"
 Const cdoSendpassword = " http://schemas.microsoft.com/cdo/configuration/sendpassword "
 Const cdoSMTPPickup = "http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory"

'Here I to covert all const as String or Int32:
'e.g.      Const cdoSMTPAuthenticate As String = "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate


 Const cdoAnonymous = 0
 Const cdoSendUsingPickup = 1
 Const cdoSendUsingPort = 2
     
 Dim oMessage, x
 Dim oConfiguration

 x =1
 SendEmail = False     ''Don't know what is this
     
 Set oConfiguration = Server.CreateObject("CDO.Configuration")
 With oConfiguration.Fields
     .Item(cdoSendUsingMethod) = 2                                      'error property item is read
     .Item(cdoSMTPServer) = SMTPServer                                'error property item is read
     .Item(cdoSMTPAuthenticate) = 1                                       'error property item is read
     .Item(cdoSendusername) = "validdomainuseraccount"     'error property item is read
     .Item(cdoSendpassword) = "pwd"                                     'error property item is read
   If Trim(SMTPServer) = "" Then
     .Item(cdoSendUsingMethod) = cdoSendUsingPickup          'error property item is read
     .Item(cdoSMTPPickup) = "C:\inetpub\mailroot\pickup"        'error property item is read
   Else
     .Item(cdoSendUsingMethod) = cdoSendUsingPort               'error property item is read
   End If
   .Update
 End With
  Set oMessage = Server.CreateObject("CDO.Message")
  With oMessage
   Set .Configuration = oConfiguration
      .From     = "al@mome.com.au"
      .To       = "al@work.com.au"
      .Subject  = "Test SendCDOASP"
      .TextBody = "Body"
      .Send
 End With

 Set oMessage = Nothing
 Set oConfiguration = Nothing

 If Err.Number = 0 Then
   SendEmail = True
  End If

Thank you
ASKER CERTIFIED SOLUTION
Avatar of Zhaolai
Zhaolai
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of dpd3891

ASKER

Thanks Zhaolai, it works............:)

but now it's throwing exception "The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available"

When I try to use smtp server directly, it works...........but I using through my code it doesn't and throws exception........

Do anybody have idea?

Thank you.
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of dpd3891

ASKER

sending email worked with other option.