Fixed SMTP Mail Send Validation Error
2010-05-09 02:07
513 查看
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);
相关文章推荐
- AX fail to send mail by SMTP , COM error code 0x80040211, 0x8004020f
- login SMTP send mail error : Unable to read data from the transport connection: net_io_connectionclosed
- com.sun.mail.smtp.SMTPSendFailedException: 503 Error: need EHLO and AUTH first !
- smtpClient发邮件错误:不允许使用邮箱名称。 服务器响应为: You are not authorized to send mail, authentication is required
- 解决530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MA
- 免费SMTP邮件服务:Mandrill,Sendgrid,Mailjet,Postmarkapp,MailChimp
- 用Telnet 来用smtp发邮件。。 send mail by SMTP server
- Send mail using Gmail SMTP in Magento
- smtpClient发邮件错误:不允许使用邮箱名称。 服务器响应为: You are not authorized to send mail, authentication is required
- com.sun.mail.smtp.SMTPSendFailedException: 553 Mail from must equal authorized user
- com.sun.mail.smtp.SMTPSendFailedException: 554 DT:SPM 163 smtp10,DsCowABX3qJtagRZBXMsBA--.8416S2 149
- Send Error:不允许使用邮箱名称。 服务器响应为: You are not authorized to send mail, authentication is required
- com.sun.mail.smtp.SMTPSendFailedException: 554 MI:SPB UserReject 0,smtp7
- jenkins配置邮件 -- com.sun.mail.smtp.SMTPSenderFailedException: 550 5.7.1 Client does not have permissions to send as this sender
- A Client to Send SMTP Mail
- How to Send an Email Using UTL_SMTP with Authenticated Mail Server
- mailsend - Send mail via SMTP protocol from command line
- com.sun.mail.smtp.SMTPSendFailedException: 554 DT:SPM 163 smtp11,D8CowAC3cuDofbZXKWsnCw--.47929S2 14
- How to Send an Email Using UTL_SMTP with Authenticated Mail Server. (文档 ID 885522.1)
- javaMail SMTPSendFailedException: 554 DT:SPM 163 smtp4