+1 vote

Hello,

I'm using MAIL library in my ASP.NET (WebForms) project and I have a
problem with sendig email, which must be encrypted and signed.

The problem is in line .SignWith( ...

There is no any exception, but I get only

502 - Web server received an invalid response while acting as a gateway or
proxy server. There is a problem with the page you are looking for, and it
cannot be displayed. When the Web server (while acting as a gateway or
proxy) contacted the upstream content server, it received an invalid
response from the content server.

On localhost everything ok.

Here is my code:

try
{
      if (File.Exists(clientCert) && File.Exists(encryptCert))
      {
         mail = Mail.Text(EmailBodyString)
             .Subject(this.Subject)
             .AddAttachment(xmlFile)
             .From(new MailBox(this.SenderEmailAddress))
             .To(new MailBox(this.ReceiverEmailAddress))
             .EncryptWith(new X509Certificate2(encryptCert))
             .SignWith(new X509Certificate2(
                clientCert,
                this.SenderCertificatePassword))
             .Create();
       }
 }
 catch (Exception ex)
 {
    throw ...

}

Best regards

by

1 Answer

0 votes
 
Best answer

Try using X509KeyStorageFlags.MachineKeySet when you access signing certificate:

X509Certificate2(fullPath, password, X509KeyStorageFlags.MachineKeySet)
by (301k points)
selected by
...