views:

751

answers:

5

I have an ASP.NET program that sends a confirmation email with the following code:

 String msgTxt = "My Message";      
 try
 {
      MailMessage message = new MailMessage();
      message.From  = new MailAddress("[email protected]");
      message.To.Add(new MailAddress(emailParam));
      message.Bcc.Add(new MailAddress("[email protected]"));
      message.Subject   = "Your Nutrition Prescription";
      message.Body  = msgTxt; 

      SmtpClient client = new SmtpClient();
      client.Send(message);
 }
 catch (Exception ex)
 {     
 }

The web.config file has this:

<system.net>  
    <mailSettings>  
       <smtp>  
       <network   
           host="localhost"   
           port="25" />
       </smtp>
    </mailSettings>
</system.net>

And my IIS is set to run on Port 25 (I can telnet in and test it, and it sends just fine by telnet).

Can someone direct me somewhere else to look for the problem?

+1  A: 

Have you tried setting the SMTP Server and Port via the alternate SmtpClient constructors? At least that would tell us the problem isn't the configuration file.

int port = 1234;    
SmtpClient client = new SmtpClient("mail.mydomain.com", port);
client.Send(message);
Brad Barker
+1  A: 

Is the server you're running your code on set up as an SMTP relay in your email environment? This can be an issue in corporate / enterprise settings in particular.

MikeBev
A: 

Hi

Have you tried to specify the deliveryMethod attribute of the smtp element?

<system.net>  
    <mailSettings>  
       <smtp deliveryMethod="network">  
          <network   
              host="localhost"   
              port="25" />
       </smtp>
    </mailSettings>
</system.net>
Tor Haugen
A: 

Hi,

Are you actually getting an exception? If not, your mail is probably being accepted, but just not sent to the final destination.

Check the mailroot\badmail directory. It might be in there with a possible explanation of the problem (usually DNS resolution).

You can also enable logging for System.Net.Mail. Here is a link I wrote with more info: http://www.systemnetmail.com/faq/4.10.aspx

Cheers!

Dave

dave wanta
A: 

i have the same problema