CDO Object in Web Services using VB.NET

When I was using SMTP to send email on web services. i had experienced the error "Could not access'CDO.Message' " so many times. Finally i had resolved by specifying the localhost as default server. And by the following suggestion on IIS MMC.

Suggestion 1

If you are using "localhost" or "127.0.0.1" as the SmtpMail.SmtpServer, you may not have permissions to relay through the IID SMTP Service. To allow access, open up the IIS Admin MMC. Locate the SMTP Virtual Server, and right-click, then select Properties. On the Access tab, click the Relay button. In the Relay Restrictions dialog, grant your IP address (127.0.0.1) to the Computers listbox. Close down all dialogs, and restart the SMTP Service.

Suggestion 2

If you are using "localhost" or "127.0.0.1" as the SmtpMail.SmtpServer, make sure Anonymous access is allowd. To allow access, open up the IIS Admin MMC. Locate the SMTP Virtual Server, and right-click, then select Properties. On the Access tab, click the Authentication button. Be sure "Anonymous Access" is the only checkbox checked. Close down all dialogs, and restart the SMTP Service. 

And try this function to send emails using SMTP.

  1. <WebMethod()> _  
  2. Public Function SendErrorToComany() As String  
  3.    Try  
  4.        Dim insMail As New MailMessage  
  5.        With insMail  
  6.            .From = [email protected]  
  7.            .To = [email protected]  
  8.            .Subject = "Body of the message"  
  9.            .Body = pErr  
  10.        End With  
  11.        SmtpMail.SmtpServer = "localhost"  
  12.        SmtpMail.SmtpServer.Insert(0, "127.0.0.1")  
  13.        SmtpMail.Send(insMail)  
  14.        Return "1"  
  15.    Catch err As Exception  
  16.        Return err.StackTrace & err.Message & err.Source  
  17.    End Try  
  18. End Function  

Up Next
    Ebook Download
    View all
    Learn
    View all