Thursday, March 22, 2012

SMTPMail error: "Could not access CDO.Message object."

It seems this error is new since installing the 1.1 framework. The code was running just fine before. Here's the code...standared stuff...SMTPServer is defined in the web.config file as 'localhost' and details.email is the user's email pulled from the database. It's getting properly populated.


//Construct message
MailMessage msg = new MailMessage();
msg.BodyFormat = MailFormat.Html;
msg.From = "admin@dotnet.itags.org.mydomain.com";
msg.To = details.email;
msg.Subject = "New User Profile Info from mydomain.com";
msg.Body = emailDetails;

//send message
SmtpMail.SmtpServer = ConfigurationSettings.AppSettings["SMTPServer"];
try
{
SmtpMail.Send(msg);
return String.Empty;
}
catch(Exception e)
{
return e.Message;
}

The SMTP service is installed and running. I've enabled logging and ther result of one attempt to send a message looks like this:

18:12:46 127.0.0.1 HELO - 250
18:12:46 127.0.0.1 MAIL - 250
18:12:46 127.0.0.1 RCPT - 550

I read a passing reference to setting permissions for the aspnet user on the mailroot folder...is this necessary? I never had to before.

Any help would be greatly appreciated. Thanks-
chlockHi,

What operating system are you running?
Are you using SMTP Virtual Server that comes with Win XP.
If yes please check out if you already properly configure the SMTP in IIS
There are a few things that can you throw you off with CDOSYS. Make sure that the c:\inetpub\mailroot\pickup folder has write permissions for the aspnet and possibly IUSR depending on if you have impersonation on or not. Within IIS SMTP make sure you set 127.0.0.1 to allow relay traffic through.

If you don't get it working with these suggestions, I would download FileMon from www.sysinternals.com, run it for a minute while refreshing your page and do a search for "denied". This will tell you what permission is denied.

There are a couple other ideas if you still run into a brick wall. I have a unique KB article I can dig up about some machineKey settings if you don't it working from this.
Thanks for taking an interest, guys...managed to solve this one on my own. This was what you call an 'operator headspace error.'

I'll post my fix, for those that may come after looking for answers. BTW, I'm running Windows 2000 Professional.

1. OpenInternet Services Manager from theControl Panel.
2. Right click on theDefault SMTP Virtual Server and selectProperties.
3. Select theAccess tab.
4. Click on theRelay button.
5. For security reasons, underSelect which computers may relay through this virtual server, I have selectedOnly in the list below. UncheckAllow all computers which successfully authenticate to relay, regardless of the list above.
6. Click the Add button.
7. SelectSingle computer and enter the localhost address of127.0.0.1
8. ClickOK
9. ClickOK again to exit Relay Restrictions dialog
10. ClickOK again to close the SMTP Virtual Server properties

A brief explanation on the security issues involved, for those of you who are developing on the same machine that your IIS is running on. I've had this happen to me before, so I learned the hard way. When you enable the SMTP server with it's default settings, you run the risk of allowing some idiot to bounce his spam off your server. I woke up one day to find over 10,000 emails in my queue and my hard drive running non stop trying to relay them all for some fools selling herbal Viagra all over the world. So be sure to restrict access to your server as much as possible.

Happy coding-
chlock

0 comments:

Post a Comment