Please Help: Failure sending Email (C#.Net 3.5)

I pretty much have the same as what you have provided, and I’ve also tried multiple ways of configuring the mail settings (different sites have them coded slightly different and in different formats etc) but the same error occurs.

What basically happens, to give a bit of Background which may help, its a General Enquiries form upon clicking submit - it stores the data inthe SQL DB via LINQ to SQL to fires this Email script… I am using my Hotmail account for test purposes - I wasnt if that was causing any problems? using the Smtp.live.com and my full email address as the username - as thats what it requires when you login to Hotmail/Windows Live, right? I have tried it without the @hotmai… to the same result

Providing C# / Web.Config code then Error:

C# (GeneralEnq.cs from GeneralEnq.aspx):


private void GeneralEnquirySend()
    {
        MailMessage msg = new MailMessage();

        msg.From = new MailAddress("name@hosting.com");
        msg.To.Add(new MailAddress(txtEmail.Text));

        msg.Subject = "Your General Enquiry";
           
        msg.Body = "<font size=3 face=ariel>Your General Enquiry</font><p />" +
            "<font size=2 face=ariel> You sent the following details:<P />" +
            "Forename: " + txtForename + "<br/>" +
            "Surname: " + txtSurname + "<br />" +
            "Address 1: " + txtAddress1 + "<br />" +
            "Address 2: " + txtAddress2 + "<br />" +
            "Town/City: " + txtTownCity + "<br />" +
            "Post Code: " + txtPostCode + "<br />" +
            "Telephone: " + txtTelephone + "<br />" +
            "Mobile: " + txtMobile + "<br />" +
            "E-Mail: " + txtEmail + "<br />" +
            "Comment: " + txtComment + "<br />" +
            "We try to answer all General Enquiries within 48 hours via Telephone;<br />If there is no answer or number provided we then contact via E-Mail. <p />Do Not Reply To This Email.";

        SmtpClient client = new SmtpClient();
        client.Send(msg);
    }

WEB.CONFIG File:


<system.net>

    <mailSettings>
      <smtp from="username@hotmail.com">

        <network host="smtp.live.com" password="password" userName="username@hotmail.com" />
      </smtp>

    </mailSettings>

  </system.net>
</configuration>

Error Message (via running Debug Mode):

“SmtpException was unhandled by User Code…”

Error Message (thrown on the aspx page):


A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond myipaddress:25
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond myipaddress:25

Source Error:

Line 104:        
Line 105:        SmtpClient client = new SmtpClient();
Line 106:        client.Send(msg);
Line 107:    }
Line 108:

I am not sure whether you can use hotmail or live as smtp server. On the other hand check whether your isp blocks the smtp port 25. U can use alternate port 2525. Or ask your hosting provider about the smtp port other than 25

Yea, I also do not think you can use hotmail smtp server. You can use gmail, if you allow it in your settings.

Y not use the localhost smtp service of IIS? Then unblock outgoing packets on port 25

With the latter, (“Y not use the localhost smtp service of IIS? unblock outgoing packets on port 25”) doing it local etc - I’m unsure of how to do that? Is there any example laying round that may be of any use?

I’ll try it with Gmail first.

You can always set the .NET SMTP stuff to write it to a queue folder rather than attempt to send. Just as good for testing purposes and eliminates network issues.

Gmail makes no difference to the outcome of the error message, given in the Debug Mode of VS08, is still:


SmtpException was unhandled by user code

Failure to send...

The aspx failure message is:


Server Error in '/BookingSys' Application.
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond MYIPADDRESS:2525
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 209.85.229.109:2525

Source Error:

Line 109:            ("danielthorntonbsc@googlemail.com", "crybaby1!");
Line 110:        client.EnableSsl = true;
Line 111:        client.Send(msg);
Line 112:    }
Line 113:

:mad: Debug Mode states that the SmtpException is unhandled, am I missing some code?

Does anyone have an example of code that they know that works for me to work from?

Well, have are you trying to connect correctly? Gmail uses ssl security, so you need to user another port other than 25.

To use localhost. Just use localhost instead of smtp.live.com and no username and password. Then in iis manage, make sure SMTP relay is allowed for your pc. And that should work

Also, if you are getting that far then your SMTP code is working, you are just running into configuration issues.

Right! Well, I think it was the port number as thats all I’ve changed since in the web.config from 25 to 587 and its sending perfectly!

Thank You all for your help

This might provide a laugh also for you all :stuck_out_tongue: …I did start to panic and wonder briefly why this was happening in the Email that was eventually sent…


Your General Enquiry
You sent the following details:

Forename: System.Web.UI.WebControls.TextBox <--This
Surname: System.Web.UI.WebControls.TextBox
Address 1: System.Web.UI.WebControls.TextBox
etc...

Didn’t put the .TEXT property after it, did I… lol

Thanks a lot again its very much appreciated!

no problem.

Lol, yea I see so. I thought it might have been string vars u declared somewhere else. But dnt worry to much. I do that often. lol. So used to working with vars that I forget I need the .Text value.