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.
- <WebMethod()> _
- Public Function SendErrorToComany() As String
- Try
- Dim insMail As New MailMessage
- With insMail
- .From = [email protected]
- .To = [email protected]
- .Subject = "Body of the message"
- .Body = pErr
- End With
- SmtpMail.SmtpServer = "localhost"
- SmtpMail.SmtpServer.Insert(0, "127.0.0.1")
- SmtpMail.Send(insMail)
- Return "1"
- Catch err As Exception
- Return err.StackTrace & err.Message & err.Source
- End Try
- End Function