Fixed SMTP Mail Send Validation Error

來源:互聯網
上載者:User
The Mail Send Validation Solution :The Remote Certificate Is Invalid According To the Validation Procedure (C#)

One way to secure XML web services is using SSL. If you install a certificate that has not been issued by a trusted certification authority on the web site hosting the web service and you consume the web service from a .NET application, then you would probably get an AuthenticationException warning you that "the remote certificate is invalid according to the validation procedure". This happens because the default certificate policy only allows valid certificates and valid certificates that have expired. This post explains how to implement a custom certificate policy that determines whether the specified certificate is accepted for authentication.

You may use the CertificatePolicy property of the ServicePointManager class. When this property is set to an ICertificatePolicy interface object, the ServicePointManager uses the certificate policy defined in that instance instead of the default certificate policy. However as of version 2.0 of the .NET Framework the CertificatePolicy property of the ServicePointManager class is obsolete.

The suggested approach is using the ServerCertificateValidationCallback property of the ServicePointManager class.

1) Implement your custom certificate policy in a method that returns a Boolean value. The signature of the method must match the signature of the RemoteCertificateValidationCallback delegate. This delegate determines whether the authentication is allowed to succeed based on the Boolean value returned by your method. The method in the following code example simply allows all certificates.

using System;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

// ...

public static bool ValidateServerCertificate(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
   return true;
}

2) Create the RemoteCertificateValidationCallback delegate using the method defined in the preceding code example and assign it to the ServerCertificateValidationCallback property of the ServicePointManager class.

using System.Net;
using System.Net.Security;

// ...

ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.