"Could not access 'CDO.Message' object" - Error
In a website when I mentioned the SmtpMail.SmtpServer= “ServerIP” it was showing the following error:
“EXCEPTION Could not access 'CDO.Message' object.”
When I remove, then this was working fine.
This was showing the InnerException:
EXCEPTION System.Web.HttpException: Could not access 'CDO.Message'
object. ---> System.Reflection.TargetInvocationException: Exception
has been thrown by the target of an invocation. --->
System.Runtime.InteropServices.COMException (0x8004020F): The server
rejected one or more recipient addresses.....
This was running in a Windows 2003 Server.
Then to solve the problem what I did
- Right click on Default SMTP Virtual Server
- Select properties
- Select tab Access
- Click on Relay button
- Checked "Allow all computers...."
- And Add the Web Server's IP
Then it started working fine.
But in case different SMTP Server some time outgoing server requires authentication. In such case the following code is required:
Dim msgMail As New MailMessage
With msgMail
.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1") 'basic authentication
.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "email@email.com") 'set your username here
.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "somepassword") 'set your password here
End With