Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 21st, 2015, 06:46 PM
Authorized User
Points: 79, Level: 1
Points: 79, Level: 1 Points: 79, Level: 1 Points: 79, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2013
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Contact Form Website hosting

I have a contact form on my website, that when filled out the information is suppose to be sent to my email. It works fine on the localhost, but when on the server I get this error.

An attempt was made to access a socket in a way forbidden by its access permissions 64.233.180.109:587

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: An attempt was made to access a socket in a way forbidden by its access permissions 64.233.180.109:587

Source Error:


Line 42:
Line 43: SmtpClient mySmtpClient = new SmtpClient();
Line 44: mySmtpClient.Send(myMessage);
Line 45:

I have tried disabling my firewall, and my antivirus software. I am trying to get it to go to my gmail account using port 587. I also went into my firewall and enabled that port number with my domain address, which is www.portfoliobrown.com.


Here is a copy of my back end coding in C#

protected void SendButton_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string fileName = Server.MapPath("~/App_Data/ContactForm.txt");
string mailBody = File.ReadAllText(fileName);

mailBody = mailBody.Replace("##Name##", Name.Text);
mailBody = mailBody.Replace("##Email##", EmailAddress.Text);
mailBody = mailBody.Replace("##HomePhone##", PhoneHome.Text);
mailBody = mailBody.Replace("##BusinessPhone##", PhoneBusiness.Text);
mailBody = mailBody.Replace("##Comments##", Comments.Text);

MailMessage myMessage = new MailMessage();
myMessage.Subject = "Response from web site";
myMessage.Body = mailBody;

myMessage.From = new MailAddress("Email@gmail.com", "Stephen Brown");
myMessage.To.Add(new MailAddress("Email@gmail.com", "Stephen Brown"));

SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.Send(myMessage);

Message.Visible = true;
System.Threading.Thread.Sleep(10000);

}

So I am not sure where else to go I tried to google some answers, but couldn't fine what I was really looking for. Found some people with the same error, but not exactly the same situation as I have.

Thanks a lot for any help
Stephen
Reply With Quote
  #2 (permalink)  
Old May 22nd, 2015, 04:36 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Take a look here: http://stackoverflow.com/questions/2...access-permiss for some trouble shooting tips.

It seems like a firewall issue either on your end or on the SMTP server's side. You'll need to check with your SMTP provider what settings they require such as the port number.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old May 24th, 2015, 12:03 AM
Authorized User
Points: 79, Level: 1
Points: 79, Level: 1 Points: 79, Level: 1 Points: 79, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2013
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello

Thanks for your reply. I Have actually tried like 4 different port numbers from like 25, 26, 587, and 465. 587 seemed to work just fine when I run it on localhost. It will send everything just fine, but when I try sending it on the server, it doesnt work using that same port number. Then I tried the other three and nothing. I talk to a few different people in live chat on the server site, about my issue, but they really couldn't help me. One person said that the code that I had would only work locally for email sending and not on the server, that just didn't seem right to me. I am trying to use gmail, and everything I found online gives me those port numbers to use. I have tried disabling my firewall. I looked in my email settings to say if maybe there was something that could be disabling, but couldn't find anything.

Thanks
Stephen
Reply With Quote
  #4 (permalink)  
Old May 24th, 2015, 05:08 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Stephen,

The following works for me with Gmail:

Code:
<network enableSsl="true" host="smtp.gmail.com" password="Password"
    userName="YourAccountName@gmail.com" port="587" />
If that doesn't work, it's something on the server that prevents the mail from going out in which case it's up to your host to fix that.

BTW, depending on your Gmail settings, you may need to generate an application-specific password, which you can do here: http://bit.ly/N9Wv35.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #5 (permalink)  
Old June 4th, 2015, 02:20 AM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2015
Location: UK
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The problem may be due to the Firewall or Antivirus preventing port 587 to send the mail.
So, try making your Firewall and Antivirus off.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reg. Hosting of Website ..... Ranveer@2468 ASP.NET 3.5 Basics 1 October 21st, 2011 03:18 PM
Final Website Contact.aspx failing with error lstew452 BOOK: Beginning ASP.NET 4 : in C# and VB 4 July 28th, 2010 09:44 PM
Hosting ASP website varunbwj BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 9 January 23rd, 2010 10:13 AM
I need help with contact form iorgusu Need help with your homework? 1 September 27th, 2009 01:56 AM
Contact form? philthy BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 1 July 23rd, 2009 05:14 PM



All times are GMT -4. The time now is 02:33 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.