4 Replies - 1328 Views - Last Post: 03 August 2013 - 02:01 PM Rate Topic: -----

#1 carl_m  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 02-August 13

asp.net contact form, problem with message to mail?

Posted 02 August 2013 - 01:11 PM

Creating a contact form in my asp.net page, currently working in Visual studio 2010, and trying to send message from localhost. Tried sending to my gmail, and created an aol account and both failed. When sending to gmail, port 486 i get error:

[SocketException (0x274c): 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 173.194.71.109:486]
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +251...

Does anyone se if im missing something in the code? Or is this an error due to my localhost or visual studio environment?

Error message also points at:

Line 27: client.EnableSsl = true;
Line 28:
Line 29: client.Send(msg); <- this line, but that doesnt help me much
Line 30:
Line 31: }
----------------------------------------


<%@ Import Namespace = "System.Net.Mail" %>
<%@ Import Namespace = "System.Net" %>

 <script runat = "server" type = "text/C#"> 
     
     public void btnSend_Click(object sender, EventArgs e)
     {
         MailMessage msg = new MailMessage();

         msg.To.Add(new MailAddress("name@gmail.com"));

         msg.From = new MailAddress(txtEmail.Text);

         msg.Subject = txtSubject.Text;

         msg.Body = txtName.Text + Environment.NewLine + txtMessage.Value;

         SmtpClient client = new SmtpClient();

         client.Host = "smtp.gmail.com"; 

         client.Port = 486; // Have tried gmail and aol with 25, 486, 587  

         client.Credentials = new NetworkCredential("name@gmail.com", "mailpassword"); // Tried name@gmail.com, aol -> only username 

         client.EnableSsl = true;

         client.Send(msg);
         
     }
     
    public void btnReset_Click(object sender, EventArgs e)
    {
    
        txtName.Text = "";

        txtEmail.Text = "";

        txtSubject.Text = "";

        txtMessage.Value = "";

    }




Is This A Good Question/Topic? 0
  • +

Replies To: asp.net contact form, problem with message to mail?

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3247
  • View blog
  • Posts: 10,890
  • Joined: 12-December 12

Re: asp.net contact form, problem with message to mail?

Posted 02 August 2013 - 03:11 PM

I don't use ASP: does it have a built-in mail server that runs when testing locally?

If not, I use this one from toolheap, it's dead simple.

You might wait for an ASP person to respond. Good luck.
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3247
  • View blog
  • Posts: 10,890
  • Joined: 12-December 12

Re: asp.net contact form, problem with message to mail?

Posted 02 August 2013 - 03:22 PM

I've been reading around a little and the NetworkCredentials seem to be the username (and password) rather than an email. I may have mis-read this. Try:

client.Credentials = CredentialCache.DefaultNetworkCredentials;

but I believe this is assumed, so you might try just removing the Credentials line.

This post has been edited by andrewsw: 02 August 2013 - 03:24 PM

Was This Post Helpful? 0
  • +
  • -

#4 carl_m  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 02-August 13

Re: asp.net contact form, problem with message to mail?

Posted 03 August 2013 - 01:49 PM

View Postandrewsw, on 02 August 2013 - 03:22 PM, said:

I've been reading around a little and the NetworkCredentials seem to be the username (and password) rather than an email. I may have mis-read this. Try:

client.Credentials = CredentialCache.DefaultNetworkCredentials;

but I believe this is assumed, so you might try just removing the Credentials line.


Hi, and thanks for answering.

I think that at gmail your username is your email adress, anyway i tried both alternatives. At aol mail username is only the name before @aol.com, but tried both alternatives there too. Tried adding your line, still cant get it to work, also tried downloading program you rekommended. Seems to be a really simple and perfect program, but it just not want to run on my computer, dont know why. Maybe ill wait until i publish site somewhere and try receiving mail to there.
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3247
  • View blog
  • Posts: 10,890
  • Joined: 12-December 12

Re: asp.net contact form, problem with message to mail?

Posted 03 August 2013 - 02:01 PM

Quote

Maybe ill wait until i publish site somewhere and try receiving mail to there.

This is good advice and I neglected to mention it. We can end up spending hours trying to send an email locally, only for it to mean little when we publish.

I got caught by this myself a while back. Spent hours on it.. but refused to give up! It should be easier now though in .NET. Good luck.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1