如何通过Amazon SES获取Mono 4.2代码以发送电子邮件?

时间:2017-04-21 17:07:34

标签: ssl mono smtp x509certificate amazon-ses

我在Ubuntu 16.04.2 LTS上运行Mono(版本4.2.1)代码;该代码尝试使用Amazon SES发送电子邮件失败。从其他搜索中我读到错误是由于证书不存在于单一信任存储中。修复此问题的命令是: mozroots --import --ask-remove

接下来是:

certmgr -ssl smtps://email-smtp.eu-west-1.amazonaws.com:587

(因为email-smtp.eu-west-1.amazonaws.com是我使用的SMTP服务器;在端口587上)

第一个命令工作正常,并将162个证书导入我的商店。 第二个命令失败并出现异常。我究竟做错了什么?

这是堆栈跟踪:

Unhandled Exception:
System.IO.IOException: The authentication or decryption has failed. ---> System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: The authentication or decryption has failed.
  at Mono.Security.Protocol.Tls.RecordProtocol.EndReceiveRecord (IAsyncResult asyncResult) <0x402e7020 + 0x00132> in <filename unknown>:0
  at Mono.Security.Protocol.Tls.SslClientStream.SafeEndReceiveRecord (IAsyncResult ar, Boolean ignoreEmpty) <0x402e6f50 + 0x00031> in <filename unknown>:0
  at Mono.Security.Protocol.Tls.SslClientStream.NegotiateAsyncWorker (IAsyncResult result) <0x402e3aa0 + 0x00225> in <filename unknown>:0
  --- End of inner exception stack trace ---
  at Mono.Security.Protocol.Tls.SslClientStream.EndNegotiateHandshake (IAsyncResult result) <0x402e7cf0 + 0x000ec> in <filename unknown>:0
  at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) <0x402e7a40 + 0x0007f> in <filename unknown>:0
  --- End of inner exception stack trace ---
  at Mono.Security.Protocol.Tls.SslStreamBase.EndNegotiateHandshake (Mono.Security.Protocol.Tls.InternalAsyncResult asyncResult) <0x402e1190 + 0x0007b> in <filename unknown>:0
  at Mono.Security.Protocol.Tls.SslStreamBase.NegotiateHandshake () <0x402da8b0 + 0x000b6> in <filename unknown>:0
  at Mono.Security.Protocol.Tls.SslStreamBase.Write (System.Byte[] buffer, Int32 offset, Int32 count) <0x402da4d0 + 0x000af> in <filename unknown>:0
  at System.IO.StreamWriter.Flush (Boolean flushStream, Boolean flushEncoder) <0x7f07ce354da0 + 0x000fa> in <filename unknown>:0
  at System.IO.StreamWriter.Flush () <0x7f07ce354d70 + 0x0001f> in <filename unknown>:0
  at Mono.Tools.CertificateManager.GetCertificatesFromSslSession (System.String url) <0x402a43e0 + 0x00357> in <filename unknown>:0
  at Mono.Tools.CertificateManager.Ssl (System.String host, Boolean machine, Boolean verbose) <0x402a39f0 + 0x0013a> in <filename unknown>:0
  at Mono.Tools.CertificateManager.Main (System.String[] args) <0x4029ed70 + 0x004f0> in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.IOException: The authentication or decryption has failed. ---> System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: The authentication or decryption has failed.
  at Mono.Security.Protocol.Tls.RecordProtocol.EndReceiveRecord (IAsyncResult asyncResult) <0x402e7020 + 0x00132> in <filename unknown>:0
  at Mono.Security.Protocol.Tls.SslClientStream.SafeEndReceiveRecord (IAsyncResult ar, Boolean ignoreEmpty) <0x402e6f50 + 0x00031> in <filename unknown>:0
  at Mono.Security.Protocol.Tls.SslClientStream.NegotiateAsyncWorker (IAsyncResult result) <0x402e3aa0 + 0x00225> in <filename unknown>:0
  --- End of inner exception stack trace ---
  at Mono.Security.Protocol.Tls.SslClientStream.EndNegotiateHandshake (IAsyncResult result) <0x402e7cf0 + 0x000ec> in <filename unknown>:0
  at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) <0x402e7a40 + 0x0007f> in <filename unknown>:0
  --- End of inner exception stack trace ---
  at Mono.Security.Protocol.Tls.SslStreamBase.EndNegotiateHandshake (Mono.Security.Protocol.Tls.InternalAsyncResult asyncResult) <0x402e1190 + 0x0007b> in <filename unknown>:0
  at Mono.Security.Protocol.Tls.SslStreamBase.NegotiateHandshake () <0x402da8b0 + 0x000b6> in <filename unknown>:0
  at Mono.Security.Protocol.Tls.SslStreamBase.Write (System.Byte[] buffer, Int32 offset, Int32 count) <0x402da4d0 + 0x000af> in <filename unknown>:0
  at System.IO.StreamWriter.Flush (Boolean flushStream, Boolean flushEncoder) <0x7f07ce354da0 + 0x000fa> in <filename unknown>:0
  at System.IO.StreamWriter.Flush () <0x7f07ce354d70 + 0x0001f> in <filename unknown>:0
  at Mono.Tools.CertificateManager.GetCertificatesFromSslSession (System.String url) <0x402a43e0 + 0x00357> in <filename unknown>:0
  at Mono.Tools.CertificateManager.Ssl (System.String host, Boolean machine, Boolean verbose) <0x402a39f0 + 0x0013a> in <filename unknown>:0
  at Mono.Tools.CertificateManager.Main (System.String[] args) <0x4029ed70 + 0x004f0> in <filename unknown>:0

1 个答案:

答案 0 :(得分:0)

certmgr的常见故障之一是不使用sudo运行它。它产生了异常,这是一个非常误导。 在macOS / Linux上: certmgr -ssl smtps://email-smtp.eu-west-1.amazonaws.com:587 将产生您发布的确切错误。 使用sudo: sudo certmgr -ssl smtps://email-smtp.eu-west-1.amazonaws.com:587 结果是: X.509证书v3    发自:C = US,O = Equifax,OU = Equifax安全证书颁发机构    发布于:C = US,O = GeoTrust Inc.,CN = GeoTrust Global CA.    有效期:5/21/2002 4:00:00 AM    有效期至:8/21/2018 4:00:00 AM    ***警告:证书签名无效*** 将此证书导入CA存储中?是的 X.509证书v3    发自:C = US,O = GeoTrust Inc.,CN = GeoTrust Global CA.    颁发给:C = US,O = Google Inc,CN = Google Internet Authority G2    有效期:2015年4月1日上午12:00:00    有效期至:12/31/2017 11:59:59 PM    ***警告:证书签名无效*** 将此证书导入CA存储中?是的 X.509证书v3    发自:C = US,O = Google Inc,CN = Google Internet Authority G2    签发:C = US,S = California,L = Mountain View,O = Google Inc,CN = smtp.gmail.com    有效期:4/12/2017 1:28:00 PM    有效期至:7/5/2017 1:28:00 PM 将此证书导入AddressBook商店?是的 3个证书添加到商店。 注意:确保您对导入问题回答“是”。