2

I have hosted a website from Godaddy hosting in Windows ASP.net and have purchased an email also from there as well. On that website, there is a ContactUs Page in which any visitor could fill in his details and Submit. For this I am internally using my personal gmail id as 'From' and my info email ID as 'To' to send the email. I am using the sample code they provided on their website as this link.

But I am getting this error:

An exception of type 'System.Net.Mail.SmtpException' occurred in System.dll but was not handled in user code. Additional information: Service not available, closing transmission channel. The server response was: Cannot connect to SMTP server 72.167.234.197 (72.167.234.197:25), connect error 10060

On client.Send(message)

This is my web.config entry as per that link:

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

And this is my code to send email:

        StringBuilder body = new StringBuilder();
        body.AppendLine("<h3>New Query Received:</h3>");
        body.AppendLine();
        body.AppendFormat("Name : {0}<br />", txtName.Text);
        body.AppendFormat("Email : {0}<br />", txtEmail.Text);
        body.AppendFormat("Phone : {0}<br />", txtMobile.Text);
        body.AppendFormat("Query : {0}<br />", txtQuery.Text);

        MailMessage message = new MailMessage();
        message.From = new MailAddress("manish.rnsconsultancy@gmail.com");

        message.To.Add(new MailAddress("info@rns-consultancy.com"));

        message.Subject = "New Query from Website";
        message.Body = body.ToString();

        SmtpClient client = new SmtpClient();
        client.Send(message);

Can anyone please help me in this matter, I am stuck on this as their customer support doesn't know other than that link. I tried switching the emails as From and To also, but got the same error.

Hemant Sisodia
  • 488
  • 6
  • 23

2 Answers2

1

try this code to send email.

Send email using System.Net.Mail To send mail using System.Net.Mail, you need to configure your SMTP service in your application's web.config file using these values for mailSettings:

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

The network rule's value will be used when you instantiate an SmtpClient in your code.

PS: Please change port 3535 if you have problems with 25

C# code example You can then use code similar to this to send email from your application:

MailMessage message = new MailMessage();
message.From = new MailAddress("your email address");

message.To.Add(new MailAddress("your recipient"));

message.Subject = "your subject";
message.Body = "content of your email";

SmtpClient client = new SmtpClient();
client.Send(message);
ravi polara
  • 564
  • 3
  • 14
  • I tried your code earlier too, with 25, I am getting the error in my original question. With port 3535, I am getting error as : "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 72.167.234.197:3535" – Hemant Sisodia Jan 05 '19 at 08:43
  • ohh, but you contact GOGADDY Support Team. – ravi polara Jan 05 '19 at 08:46
  • Didnt get any help from them, they only provide the documented solution which is not working in my case. And when I changed the port to 80, it worked on localhost, but gave error on live website with error as "No permission to assign port in web.config" – Hemant Sisodia Jan 05 '19 at 09:04
  • For some reason port 25 stopped working without explanation, generating a timeout error . Switching to port 3535 worked well. – Travis J Oct 02 '20 at 19:44
0

after checking you DNS record i found

smtp.asia.secureserver.net

Use this code and Add your password

var message = new MailMessage();

message.To.Add(new MailAddress("info@rns-consultancy.com"));
message.From = new MailAddress("info@rns-consultancy.com");

message.Subject = "Subject";
message.Body = "Body";

var smtpClient = new SmtpClient();



smtpClient.Host = "smtp.asia.secureserver.net";
smtpClient.Port = 25;
smtpClient.EnableSsl = false;
smtpClient.UseDefaultCredentials = false; 

smtpClient.Credentials =
     new NetworkCredential("info@rns-consultancy.com", "Password");

//smtpClient.Port = 465;
//smtpClient.EnableSsl = true;

//smtpClient.Timeout = 10000; 
// don't use 100000 in production it's 2 match 
//, just for testing
smtpClient.Timeout = 100000;

smtpClient.Send(message);

refrences

Mohamed Elrashid
  • 8,125
  • 6
  • 31
  • 46
  • Nop, getting this error by this code: {"Unable to read data from the transport connection: net_io_connectionclosed."} – Hemant Sisodia Jan 03 '19 at 07:12
  • @HemantSisodia is info@rns-consultancy.com Assign SMTP relay ? see https://in.godaddy.com/help/assign-smtp-relays-20153 – Mohamed Elrashid Jan 03 '19 at 07:15
  • do still need help ? – Mohamed Elrashid Jan 03 '19 at 15:04
  • I dont see "Additional Options" in my "GoDaddy Business Email" settings. When I click on "Manage", I only see options to change password, Recheck DNS and Delete Account. – Hemant Sisodia Jan 05 '19 at 08:36
  • do you still need help ? – Mohamed Elrashid Jan 07 '19 at 22:47
  • Hi Mohamed, Thanks for your reply. But I used your code and still it is giving me permission error.: Security Exception Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. – Hemant Sisodia Jan 08 '19 at 07:53
  • @HemantSisodia SmtpPermission meas you server can't use Port 465 , I just updated the code – Mohamed Elrashid Jan 08 '19 at 16:17
  • After using Port 25, I am getting this error now: An attempt was made to access a socket in a way forbidden by its access permissions 182.50.144.66: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: An attempt was made to access a socket in a way forbidden by its access permissions 182.50.144.66:25 – Hemant Sisodia Jan 09 '19 at 09:07
  • The code runs fine on my local machine, but gives these errors when I publish my code on the website hosted on godaddy server – Hemant Sisodia Jan 09 '19 at 11:25
  • could you please tell me what else I could try? – Hemant Sisodia Jan 11 '19 at 05:20
  • Getting the same error with this too: System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions 182.50.145.3:25 – Hemant Sisodia Jan 11 '19 at 07:04
  • add Credentials after UseDefaultCredentials – Mohamed Elrashid Jan 11 '19 at 10:47
  • I tried this too with smtpout.asia.secureserver.net but no success. Do you know anything else? – Hemant Sisodia Jan 15 '19 at 06:13