是否有一种方法可以从Outlook中处理/关闭对话框,同时发送具有加密的电子邮件(使用C#WPF)?
我有一个C#WPF应用程序,它的功能之一是通过本地Outlook/帐户发送一系列电子邮件。它使用Microsoft.office.interop.outlook com。问题是我需要加密电子邮件。我正在使用以下方法来处理它:
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)
{
(...)
}
由于我将这些电子邮件发送到公司的帐户,因此,从理论上讲,所有员工都应拥有有效的证书(PKI卡)。实际上,有些人肯定不会遵守这一要求(出于某些原因)。因此,当我测试该应用程序,模拟此类问题时,Outlook显示对话框询问决定:
Microsoft Outlook在加密此消息时存在问题,因为以下收件人缺少或无效的证书,或冲突或不支持的加密功能:地址)。 继续将加密并发送消息,但列出的收件人可能无法阅读它。
[发送未加密的] [继续] [cancel]
该应用程序正在等待着用户决定。我发现对用户的不便。
如果发生此类问题,我要么看到:
- 禁用此类对话框并确保将异常抛出,因此我可以
- 以自动化的方式跟踪有问题的帐户,或...以某种方式处理此类对话框。
注册表更改不是一个选择。
有人可以帮忙吗?
问候, 克里斯
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Outlook Object模型不能自动抑制此类对话框。
The Outlook object model doesn't provide anything for suppressing such dialogs automatically.