Microsoft.net has provided the MailMessage class for sending emails. Althought the use of this class is fairly simple and sending emails is a straight forward but sometimes you will face different errors. In this article I have suggested some resolutions of the well known "CDO.message object" error.

 

Introduction:

Microsoft.net has provided the MailMessage class for sending emails. Even though sending emails using the MailMessage class is fairly simple one always faces different problems. Among those errors is "Could not access CDO.message object". This error is considered the nightmare of all error while sending emails.

In this article we will see different approaches that can resolve the nightmare. If you are unfamiliar with sending emails using MailMessage class than please check out my article Sending emails using Asp.net.


Resolutions:

There is no single resolution to this problem. The error might come because of different reasons, I will cover some of the ways that you can use to resolve it.

1) First check that if virus scan is running. These virus scanners include Norton and McAfee. Virus scanners usually checks that what email is being sent and they block emails sent by the local server. Instead of disabling the virus scanner completely you can also turn off its sending email validation settings. 

2) Check the relay settings, I have discussed relay settings in my article Sending emails using Asp.net.

3) You also need to check that if your user account has permission to send emails. Since Asp.net applications runs under the ASPNET account that account also must have permission to send emails.

4) Sometimes you will find that your emails are stuck under the C:\Inetpub\mailroot\Queue. This might be because your ISP does not allow you to send emails. You can contact your ISP and let them know the problem.

5) There is also a situation that you have the mail server name but it won't work because it allows certain permissions to send emails. If this is the case you can make minor adjustments in your code.

Instead of this code:

MailMessage mail = new MailMessage();

mail.To = EMAILTO;

mail.From = feedback.Email;

mail.Subject = SUBJECTMSG + feedback.Name;

mail.Body = feedback.Comment;

try

{

SmtpMail.SmtpServer = "mymail.something.com";

SmtpMail.Send(mail);

}

 


You can try this:

MailMessage mail = new MailMessage();

mail.To = EMAILTO;

mail.From = feedback.Email;

mail.Subject = SUBJECTMSG + feedback.Name;

mail.Body = feedback.Comment;

try

{

SmtpMail.SmtpServer = "";

SmtpMail.Send(mail);

}

 

It works in my situation maybe it can cure your nightmares too. If you are sending emails from the localhost than you can also try putting the SmtpMail.SmtpServer="";.

6) When testing that if the email is being sent or not always use the correct addresses. Don't send the email from "[email protected]". Also it is better that for testing purposes you send the email to yahoo or gmail account instead of hotmail. For some reason the email takes much longer when sent to hotmail account. 

7)  Always always always check the junk or bulk folder of your email. You will be expecting email in inbox but it might be sitting in junk folder. 

These were only few of the resolutions. If you find any other solution related to sending emails than please email me at [email protected] and I will add your entry in this article.

Happy coding !