For those of you who tried sending mail using Asp.net MailMessage class you must have encountered this error message.
"CDO Object could not be found".
There are many ways of resolving this error but here is what I did.
First make sure you include the server name. If you are sending mail from your computer than the server will be "localhost".
MailMessage mail = new MailMessage();
mail.To = _emailTextBox.Text;
mail.From = "testmail@tester.com";
mail.Subject = "Hello";
mail.Body = "Hello World";
try
{
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(mail);
_button.Text = "Mail Sent";
}
catch(Exception ex)
{
_emailTextBox.Text = ex.Message;
}
Also go to IIS and at the end you will see the Smtp settings. Right click on the "Default Smtp Virual Server" and select properties. Click on Access and than click on relay. Here you can either add the ip address or reject the ip address of any computer. I just entered one random ip address which is not allowed to see my website. You can add "127.0.0.1" in the option that says this computer can access the website.
Also click on the security tab and add the ASPNET user this will give the ASPNET user operator privilages to send emails.
No comments:
Post a Comment