I spent all day trying to figure out the CDO object error which is caused when sending emails using the MailMessage class of .NET. I solved the problem previously by just changing the relay settings but now its acting different. So I went to www.systemwebmail.com and searched for my answer. Finally I found out that McAfee virus scan was causing the problems. So I turned off the on-access scan and tried it one last time.
The error CDO object is gone now. No exception is being thrown but its been 10 minutes and I have not recieved the email that I sent. Let's wait and see what happens in the next 2-3 hours and if I recieve the email or not.
// Next day
Well I did recieved the email but not in 2-3 hours but close to 6-7 hours. It seems like when I send the email to the hotmail account it takes a lot of time to appear in the mailbox on the other hand it I send the email to the yahoo account it appears in 1 second or less. I would suggest if you are testing that the email is being sent or not use Yahoo email address as a "To" or "Target" address since yahoo is much faster in recieving emails than hotmail or google.com. Anyhow here is my final code for sending emails:
MailMessage mail = new MailMessage();
mail.To = "azamsharp@yahoo.com";
mail.From = "iamazam@hotmail.com";
mail.Subject = "Finally this is working";
mail.Priority = MailPriority.High;
mail.Body = "New Mail ";
SmtpMail.SmtpServer = "localhost";
try
{
SmtpMail.Send(mail);
}
catch(Exception ex)
{
Response.Write(ex.Message);
while( ex.InnerException != null )
{
Response.Write("--------------------------------");
Response.Write("The following InnerException reported: " + ex.InnerException.ToString() );
ex = ex.InnerException;
}
No comments:
Post a Comment