Hardik Parmar
Hardik Parmar

Reputation: 11

GoDaddy + Microsoft 365: Send email using SMTP works on locally but fails on hosted website (C# ASP.NET MVC)

Hosting: GoDaddy Windows Hosting Platform: ASP.NET MVC C# .NET Framework 4.8 Email: Microsoft 365 SMTP Settings: Host: smtp.office365.com Port: 587 DeliveryMethod: Network EnableSsl: true Credentials: Username & Password

Send email works fine when run the web application on local (IIS Express), but smtp.send() throws below error when deployed on hosting server.


{
  "ClassName": "System.Net.Mail.SmtpException",
  "Message": "**Failure sending mail.**",
  "Data": null,
  "InnerException": {
    "ClassName": "System.Net.WebException",
    "Message": "Unable to connect to the remote server",
    "Data": null,
    "InnerException": {
      "NativeErrorCode": 10013,
      "ClassName": "System.Net.Sockets.SocketException",
      "Message": "**An attempt was made to access a socket in a way forbidden by its access permissions**",
      "Data": null,
      "InnerException": null,
      "HelpURL": null,
      "StackTraceString": " at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)\\r\\n at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)",
      "RemoteStackTraceString": null,
      "RemoteStackIndex": 0,
      "ExceptionMethod": "8\\nDoConnect\\nSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\\nSystem.Net.Sockets.Socket\\nVoid DoConnect(System.Net.EndPoint, System.Net.SocketAddress)",
      "HResult": -2147467259,
      "Source": "System",
      "WatsonBuckets": null
    },
    "HelpURL": null,
    "StackTraceString": " at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6)\\r\\n at System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback)\\r\\n at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)\\r\\n at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)\\r\\n at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)\\r\\n at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)\\r\\n at System.Net.Mail.SmtpClient.GetConnection()\\r\\n at System.Net.Mail.SmtpClient.Send(MailMessage message)",
    "RemoteStackTraceString": null,
    "RemoteStackIndex": 0,
    "ExceptionMethod": "8\\nGetConnection\\nSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\\nSystem.Net.ServicePoint\\nSystem.Net.Sockets.Socket GetConnection(System.Net.PooledStream, System.Object, Boolean, System.Net.IPAddress ByRef, System.Net.Sockets.Socket ByRef, System.Net.Sockets.Socket ByRef)",
    "HResult": -2146233079,
    "Source": "System",
    "WatsonBuckets": null
  },
  "HelpURL": null,
  "StackTraceString": " at System.Net.Mail.SmtpClient.Send(MailMessage message)\\r\\n at Inol.BAL.EmailMgmt.SendTestEmail() in C:\\code\\inol\\Inol\\BAL\\EmailMgmt.cs:line 283\\r\\n at Inol.Controllers.TestEmailController.Index(TestEmailModel model) in C:\\code\\inol\\Inol\\Controllers\\TestEmailController.cs:line 30",
  "RemoteStackTraceString": null,
  "RemoteStackIndex": 0,
  "ExceptionMethod": "8\\nSend\\nSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\\nSystem.Net.Mail.SmtpClient\\nVoid Send(System.Net.Mail.MailMessage)",
  "HResult": -2146233088,
  "Source": "System",
  "WatsonBuckets": null,
  "Status": -1
}

Already tried changing port to 25, but result is same!

What am I missing to rid of forbidden access?

Upvotes: 1

Views: 251

Answers (1)

suchislife
suchislife

Reputation: 1

So, SMTP is an old service. When you use port 587 you are using EXPLICIT TLS, NOT IMPLICIT TLS.

As far as I have found, only Gmail & Rackspace support connections on port 485 so in your case is definetly port 587.

This is because the client first connects on port 587, then after username & password are successful, it upgrades the connection to TLS.

This is not the same as IMPLICT TLS which connects encrypted from the start on port 485.

If you are using port 587, I imagine you would EnableSsl: false which is a setting the often forces port 485.

Upvotes: 0

Related Questions