Question

I have a simple .net web application written in C# with Framework 2.0.

The only thing it does is call this function:

    static void SendMail(string strSubject, string strBody, string strFrom, string strTo, string strHost)
    {
        MailMessage msg = new MailMessage();
        msg.From = new MailAddress(strFrom);
        msg.To.Add(new MailAddress(strTo));

        msg.Subject = strSubject;
        msg.Body = strBody;
        msg.Priority = MailPriority.Normal;

        SmtpClient smtpClient = new SmtpClient();
        smtpClient.Host = strHost;
        smtpClient.Send(msg);
    }

It compiles and runs without errors, but I don't get an email, no matter who I send it to.

However, the strange thing is that the same program, compiled and run on my manager's computer runs fine AND sends out an email.

We are both running it on Visual Studio 2008.

The only difference between his computer and mine is that he is on Windows XP and I'm on Windows 7.

Any information would be helpful. I'm looking for things I can check.

Was it helpful?

Solution 5

Found a solution!

In my local IIS (which is version 7), there is an icon called "SMTP email". Open this, and I found that it was set to "Store e-mails in pickup directory". This must be what the previous programmer using my computer set it to. I reset it to "Deliver e-mail to SMTP server" and now all is well.

Note: the IIS does not even need to be running.

OTHER TIPS

Sounds like it could be a firewall issue. Either the firewall on your machine, or the firewall on your network. Also, check your junk folder. I know these sound simple, but the fact that it's working for your manager makes it seem like a non-code issue.

Does the XP box has access to the SMTP server?

There are 4 parameters you need to provide to your SMTP server to be able to successfully use the SmtpClient, MailMessage, etc.

  • host="SMTPServerHostName"
  • port="portNumber" (typically port 25 is used)
  • userName="username"
  • password="password"

Maybe the XP PC cannot access the SMTPServerHostName or, if you are using localhost, maybe the XP workstation doesnt have SMTP installed.

Another possibility is that, as Josh said, the host:port is blocked.

With the SmtpClient you have not set your credentials or account information so when it is trying to send the email, it cannot send it with no account information. Replace this:

SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = strHost;
smtpClient.Send(msg);

With:

SmtpClient smtpClient = new SmtpClient();
smtpclient.Credentials = new NetworkCredentials(email, password);
smtpClient.Host = strHost;
smtpClient.Send(msg);

Replace email and password with your own.

Hope this Helps!

Older XP machines may have had SMTP capabilities. I've seen this exact thing. Windows 7 has no native SMTP capabilities. I know my old XP machine had an SMTP server with IIS, and existing programs I had that did send mail, failed on Windows 7. I got tired of fighting with it in a development environment, and just lived with it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top