문제

Gmail의 SMTP 서버와 함께 C#을 사용하여 이메일을 보내려고하면이 오류가 발생합니다.

"유효성 검사 절차에 따라 원격 인증서가 유효하지 않습니다."

SSL이 활성화되었습니다

사용 된 포트는 587입니다

사용 된 서버 이름은 "smtp.gmail.com"입니다.

사용자 이름과 비밀번호가 정확합니다

Outlook Express는 동일한 설정으로 동일한 PC에서 잘 작동합니다.

C# 프로그램은 다른 장소에서도 잘 작동합니다 ... 우리는 고객 장소에서만이 오류를 얻습니다.

도움이 필요합니다 ..

감사

편집 : @Andomar, 클라이언트에서 루트 인증서는 어디에서 찾을 수 있습니까? 이것을 어떻게 고치나요?

@alnitak, system.net.mail 라이브러리를 사용하여 starttls를 어떻게 발행합니까?

@David, "(Object Sender, X509Certificate 인증서, x509chain 체인, sslpolicyerrors sslpolicyerrors")의 매개 변수로 전달합니까? "

감사합니다 David. 나는 그 줄을 추가했다. 그러나이 코드는 System.net.mail과 직접 연결되어 있지 않기 때문에 여전히 무슨 일이 일어나고 있는지에 대해 여전히 혼란스러워합니다. 문제가 사라지는 한.

도움이 되었습니까?

해결책

또한 루트 인증서가 고객의 신뢰할 수있는 루트 당국 저장소에 있는지 확인하십시오. 이것이 서비스에서 나온 경우 로컬 머신 스토어에 루트 인증서를 추가하는 것도 도움이 될 수 있습니다. 이유를 더 잘 이해하기 위해 다음 정책이 도움이된다는 것을 알게되었습니다 ...

public bool ValidateServerCertificate( object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
// No errors so continue…
if (sslPolicyErrors == SslPolicyErrors.None)
       return true;

// I’m just logging it to a label on the page, 
//  this should be stored or logged to the event log at this time. 
lblStuff.Text += string.Format("Certificate error: {0} <BR/>", sslPolicyErrors);

// If the error is a Certificate Chain error then the problem is
// with the certificate chain so we need to investigate the chain 
// status for further info.  Further debug capturing could be done if
// required using the other attributes of the chain.
      if (sslPolicyErrors == SslPolicyErrors.RemoteCertificateChainErrors)
      {
       foreach (X509ChainStatus status in chain.ChainStatus)
       {
             lblStuff.Text += string.Format("Chain error: {0}: {1} <BR/>", status.Status, status.StatusInformation);
  }
}

// Do not allow this client to communicate 
//with unauthenticated servers.
      return false;
}

정책을 추가하려면 다음을 사용하려면 응용 프로그램 도메인에 대해서만 한 번만 수행하면됩니다.

using System.Net;
...
ServicePointManager.ServerCertificateValidationCallback =
new Security.RemoteCertificateValidationCallback(ValidateServerCertificate);

정책을 사용하여 오류를 완전히 제거 할 수 있지만 문제보다 문제를 해결하는 것이 좋습니다.

다른 팁

적절한 루트 인증서가 고객의 상점에 있는지 확인하십시오. 고객의 시스템 날짜가 정확합니다.

당신은 사용하고 있습니까? STARTTLS 또는 포트 587의 연결이 SSL이 처음부터 암호화되었다고 가정합니까?

Google의 서버가 켜져 있습니다 smtp.gmail.com starttls가 필요합니다.

당신은 설정 했습니까?

 client.EnableSsl = true;

Gmail이 필요하기 때문입니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top