我使用 Chilkat .NET 4 发送了一封电子邮件。这封电子邮件使用 .pfx 文件签名并使用收件人的 .cer 文件加密。这 2 个文件存储在 Certificates mmc 的“Trusted People”文件夹中。
现在我尝试使用 Chilkat 接收和解密这封电子邮件。它有效,但电子邮件未解密。我的 .pfx 文件和发件人的 .cer 文件始终位于“受信任的人”文件夹中。我尝试使用 AddPfxSourceData 方法添加我自己的私有证书,它返回 TRUE 但没有任何反应。我使用的所有 Chilkat 对象的 LastErrorText 属性中没有任何错误。
这是我的代码(mail.Decrypted 始终为 FALSE):
MailMan pop3 = new Chilkat.MailMan();
pop3.UnlockComponent("30-day trial");
pop3.MailHost = "pop.server.net";
pop3.MailPort = 110;
pop3.PopUsername = "my@email.com";
pop3.PopPassword = "mypassword";
bool succes = pop3.AddPfxSourceFile("C:\\my_pfx.pfx, "mypfxpassword");
EmailBundle emailBundle = pop3.CopyMail();
for (int i = 0; i < emailBundle.MessageCount; i++)
{
Email mail = emailBundle.GetEmail(i);
if(mail.ReceivedEncrypted && mail.Decrypted)
Console.WriteLine(mail.Body);
else
Console.WriteLine("Cannot decrypt this mail");
}
有任何想法吗 ?
更新:我用来发送加密电子邮件的代码:
Chilkat.MailMan mailman = new Chilkat.MailMan();
mailman.UnlockComponent("30-day trial");
mailman.SmtpHost = "smtp.server.net";
mailman.SmtpUsername = "sender@mail.com";
mailman.SmtpPassword = "senderpassword";
Chilkat.Email email = new Chilkat.Email();
email.Subject = "This is an encrypted email !";
email.Body = "This is the content of a digitally encrypted mail !";
email.From = "sender@mail.com";
email.AddTo("My Recipient", "my@email.com");
// Certificate of my@email.com
Chilkat.Cert recipientCert = new Chilkat.Cert();
recipientCert.LoadFromFile("C:\\recipient_cert.cer");
email.SetEncryptCert(recipientCert);
email.SendEncrypted = true;
bool success = mailman.SendEmail(email);
if (success)
Console.WriteLine("Mail sent !");