GoDaddy Issue Solved System.Net.Sockets.SocketException

Hi friends, this is rather unusual post title for me. But I have to make sure it appears on Google search index because I was stuck with this issue yesterday and wasted about couple of hours just to solve this. I tested my code locally for C# SMTP using MVC and it worked fine. But when I upload on GoDaddy plesk hosting panel it started showing errors on Contact Us page that :

System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions godaddy

I was stuck. Office hours was about to finish and clock was saying already 6:00 PM. S#.

Enough, use this setting to over come this socket exception on GoDaddy.
The solution was rather easy. It is detailed on here. To solve this issue:

In your code use the below SMTP configuration:

code:

String message = "Name:\r\n"+Name+"Message:"+Message+"\r\n";

MailMessage mail = new MailMessage();
mail.From = new MailAddress("from@email.com");
mail.To.Add(new MailAddress("to@email.com"));

mail.Subject = "Enquiry for Godaddy Testing.";
mail.Body = message;
SmtpClient client = new SmtpClient();
client.Send(mail);

Now in the web.config file add below Mail settings:

web.config:

<configuration>
<system.web>
<compilation debug="true" targetFramework="4.6.1"/>
<httpRuntime targetFramework="4.6.1"/>
</system.web>

<system.net>
<mailSettings>
<smtp from="from@email.com">
<network host="relay-hosting.secureserver.net" port="25" />
</smtp>
</mailSettings>
</system.net>

That’s it. The mail will be sent using the from email address mentioned in the code. The mail send using this code will be delayed for few seconds but it will be delivered.

Thank You.


3 thoughts on “GoDaddy Issue Solved System.Net.Sockets.SocketException”

    1. Yes, as the code is already hosted with GoDaddy I think Authentication happens somehow. You can ask about this from their technical team. This code worked for me, only make sure web.config mailSettings is done properly.

  1. this is solution not working or me same thing done each every line fromm code and mail setting is same but this is not worrking for me

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.