I have a C# WPF application, one of its functionalities it to send series of emails through local Outlook/account. It utilizes Microsoft.Office.Interop.Outlook COM. The thing is that I need to encrypt emails. I'm handling it with following approach:
using Outlook = Microsoft.Office.Interop.Outlook;
(...)
Outlook.Application olkApp = new Outlook.Application();
Outlook.MailItem otlMail = olkApp.CreateItemFromTemplate(templateFullPath) as Outlook.MailItem;
otlMail.To = (...)
try
{
const string PR_SECURITY_FLAGS = http://schemas.microsoft.com/mapi/proptag/0x6E010003";
long prop = Convert.ToInt64(otlMail.PropertyAccessor.GetProperty(PR_SECURITY_FLAGS));
var ulFlags = 0x0;
ulFlags = (ulFlags | 0x1); // SECFLAG_ENCRYPTED
//ulFlags = (ulFlags | 0x2); // SECFLAG_SIGNED
otlMail.PropertyAccessor.SetProperty(PR_SECURITY_FLAGS, ulFlags);
}
catch (Exception ex)
(...)
try
{
otlMail.Send();
}
catch (Exception ex)
{
(...)
}
Since I send these emails over to company's accounts, in theory all employees should have valid certificates (PKI card). In practice some folks for sure will not comply that requirement (for some reasons). So, when I'm testing the app, simulating such problem, the Outlook displays a dialog asking for decision:
Microsoft Outlook had problems encrypting this message because the following recipients had missing or invalid certificates, or conflicting or unsupported encryption capabilities: (some email address). Continue will encrypt and send the message but listed recipients may not be able to read it.
[Send Unencrypted] [Continue] [Cancel]
The application is waiting endlessly for user decision. I find it inconvenient for user.
In case such a problem occurs I'd see either:
- disable such dialogs and ensure the exception would be thrown so that I can trace problematic accounts, or...
- handle such dialogs in an automated manner somehow.
Registry changes are not an option.
Can anybody help please?
Regards, Kris