0

I am trying to sign and send an email with MailSystem.NET.

The mail is sent with a signature but the receiving email clients won't accept the signature

Gmail error:

The sender does not match the digital signature.

Thunderbird error:

The signature does not match the message contents correctly

static void Main(string[] args)
{
    var cert = new X509Certificate2(
      @"sender.pfx",
      "password",
      X509KeyStorageFlags.MachineKeySet);

    var signer = new CmsSigner(cert)
    {
        IncludeOption = X509IncludeOption.EndCertOnly
    };

    Message message = new Message();
    message.From.Email = "sender@gmail.com";
    message.To.Add("me@gmail.com");
    message.Subject = "Subject";
    message.BodyHtml.Text = "Html";
    message.BodyText.Text = "Plain Text";
    message.BuildMimePartTree();
    message.SmimeAttachSignatureBy(signer);

    SmtpClient.SendSsl(
        message,
        "smtp.gmail.com",
        465,
        "sender@gmail.com",
        "password",
        SaslMechanism.Login);
}

How can I send mails with the correct signature?

Murray
  • 1,948
  • 1
  • 12
  • 18
  • could you try `message.From.Email = "sender@gmail.com"`, I suspect that assigning with `new Address(...)` may fill the name property of the from header, which is not part of the actual sender later. – Cee McSharpface Sep 28 '17 at 13:36
  • Same behavior either way – Murray Sep 28 '17 at 13:53
  • your code appears to match their sample just fine. positive that the certificate matches 100% ? is it a personal cert on just the mail address, or a wildcard on the sender's domain? – Cee McSharpface Sep 28 '17 at 15:18
  • positive that the certificate matches what? - I just generated it with openssl – Murray Sep 29 '17 at 08:39

0 Answers0