Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 21st, 2015, 06:46 PM
Authorized User
 
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
 
Old May 22nd, 2015, 04:36 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!
 
Old May 24th, 2015, 12:03 AM
Authorized User
 
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
 
Old May 24th, 2015, 05:08 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!
 
Old June 4th, 2015, 02:20 AM
Registered User
 
Join Date: Jun 2015
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.





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.