none
System.Net.Mail.SmtpException: Transaction failed. The server response was: 5.7.1 <unknown[IP ADDRESS HERE]>: Client host rejected: Access denied RRS feed

  • Question

  • I have been using System.Net.Mail.SmtpClient for years and have always found a solution to all trivial problems related to authentication and secure connections however it has been now weeks that I am struggling to get my a new mail server to work with the library and am failing.

    Part of the stack of the problem is below:
    -----

    System.Net.Mail.SmtpException: Transaction failed. The server response was: 5.7.1 <unknown[IP ADDRESS HERE]>: Client host rejected: Access denied

       at System.Net.Mail.RecipientCommand.CheckResponse(SmtpStatusCode statusCode, String response)

       at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)

       at System.Net.Mail.SmtpClient.Send(MailMessage message)

    -----

    I have tried all the combinations and sequences with EnableSsl, Credentials, UseDefaultCredentials, etc etc but I am still faced with this problem.

    The email server provider told that you must connect using STARTTLS and System.Net.Mail is known to have issues somehow. I further found that the server only support AUTH=PLAIN which may also be causing the problem.

    Please note that it is not a relay related error as I have tested the same working with almost all other Client apps such as Outlook, Gmail, iOS, etc.

    I tried to debug the code by stepping into .NET Code and after much digging, I think it is because there is no matching code for the authenitcationModules such as AUTH=PLAIN.

    Any help is much appreciated.


    Sunday, April 23, 2017 3:01 PM

All replies

  • You can try set port to 587 and see if the server also supports explicit SSL without telling you.
    Monday, April 24, 2017 1:53 AM
    Answerer
  • Alternatively, try add reference to System.Web.dll, and use System.Web.Mail to send it.

    With reference from this blog, System.Web.Mail uses CDO and does support implicit SSL.

    Monday, April 24, 2017 2:00 AM
    Answerer
  • I have already set the port number 587 as without it, the handshake does not happen and it gives another error message that you must have SSL encrypted connection.
    Monday, April 24, 2017 9:26 AM
  • It would be like going into the past, years back into past, and using obsolete library. Anyways, let me give it a try and come back with results.
    Monday, April 24, 2017 9:27 AM
  • Just in case you've not found how to do it, to use implicit SSL in System.Web.Mail, you have to add the following field in each MailMessage to configure it to use implicit SSL.

    System.Web.Mail.MailMessage mailMsg = new System.Web.Mail.MailMessage();
    mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl",true);


    If you'd like to try 3rd party solutions, AIM is free opensource library you can use. To use it just download the library from NuGet.
    Monday, April 24, 2017 9:57 AM
    Answerer