Hello,
the MailMessage
does not support logging yet. Can you try to call Decrypt()
method omitting the CanDecrypt
check? This shall generate an error, by which we might be able to determine what is causing the problem.
You can also create custom certificate finder by implementing ICertificateFinder
interface in custom created class and output some more information which goes to log file. It can be done the following way:
class CertFinder : ICertificateFinder
{
public CertificateChain Find(SubjectIdentifier subjectIdentifier, CertificateStore additionalStore)
{
if (subjectIdentifier.Issuer != null)
{
Console.WriteLine("Issuer:");
Console.WriteLine(subjectIdentifier.Issuer.ToString());
}
if (subjectIdentifier.SerialNumber != null)
{
Console.WriteLine("Sub identifier:");
Console.WriteLine(Convert.ToBase64String(subjectIdentifier.SerialNumber));
}
if (subjectIdentifier.SubjectKeyIdentifier != null) {
Console.WriteLine("Sub key:");
Console.WriteLine(Convert.ToBase64String(subjectIdentifier.SubjectKeyIdentifier));
}
if (subjectIdentifier.PublicKey != null)
{
Console.WriteLine("Pub key:");
Console.WriteLine(Convert.ToBase64String(subjectIdentifier.PublicKey));
}
if (subjectIdentifier.PublicKeyAlgorithm != null)
{
Console.WriteLine("Pub key alg:");
Console.WriteLine(subjectIdentifier.PublicKeyAlgorithm.ToString());
}
return CertificateFinder.Default.Find(subjectIdentifier, additionalStore);
}
}
And then add the code below to your code:
using (var ssh = new Ssh())
{
MailMessage mail = new MailMessage();
mail.Load(@"c:\email.eml");
mail.CertificateFinder = new CertFinder();
if (mail.IsEncrypted)
{
Console.WriteLine("Encrypted mail");
Console.WriteLine("CanDecrypt: {0}", mail.CanDecrypt);
try
{
mail.Decrypt();
}
catch (Exception x)
{
Console.WriteLine(x);
}
}
else
{
Console.WriteLine("Can not be decrypted");
}
}