保存(另存为)数字签名邮件时,Outlook 会通过消息框问题提示用户“您即将以不安全的格式保存数字签名电子邮件。是否要继续?”。
我需要 Outlook 保存消息而不显示消息框。有没有办法通过 Outlook 设置、注册表项或以编程方式抑制此消息?
另一个复杂之处是 Outlook 是通过服务执行的。我可以通过多种方式成功地以编程方式响应消息框,但当作为服务运行时,它们都不起作用。 SendKeys、SendMessage、PostMessage 和 SendInput 在桌面上运行时都可以工作,但作为服务运行时会失败。
Process p = Process.GetProcessesByName("OUTLOOK").FirstOrDefault();
if (p != null)
{
IntPtr h = p.MainWindowHandle;
SetForegroundWindow(h);
// SendKeys works when running on the desktop, but not when running as a service.
SendKeys.SendWait("y");
// SendMessage works when running on the desktop, but not when running as a service.
SendMessage(h, WM_KEYDOWN, 0x59, 0);
// PostMessage works when running on the desktop, but not when running as a service.
PostMessage(h, WM_KEYDOWN, 0x59, 0);
// SendInput works when running on the desktop, but not when running as a service.
Input[] inputs = new Input[]
{
new Input
{
type = (int)InputType.Keyboard,
u = new InputUnion
{
ki = new KeyboardInput
{
wVk = 0,
wScan = 0x15, // Y
dwFlags = (uint)(KeyEventF.KeyDown | KeyEventF.Scancode),
dwExtraInfo = GetMessageExtraInfo()
}
}
},
new Input
{
type = (int)InputType.Keyboard,
u = new InputUnion
{
ki = new KeyboardInput
{
wVk = 0,
wScan = 0x15, // Y
dwFlags = (uint)(KeyEventF.KeyUp | KeyEventF.Scancode),
dwExtraInfo = GetMessageExtraInfo()
}
}
}
};
SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(Input)));
}
是否有抑制或响应对话框的方法? Outlook 加载项可以检测到该对话框并将其关闭吗?
仅当您从 Outlook.exe 地址空间外部访问 OOM 时,才会显示签名/加密消息的提示。
Outlook.Application
提供给 Outlook VBA 或 COM/VSTO 插件的对象是可信的,不会显示该提示。
如果使用 Redemption 是一个选项(我是其作者),则 Redemption 不会显示任何提示:您可以使用
GetMessageFromId
或 GetRDOObjectFromOutlookObject
重新打开消息。请注意,对于签名/加密的消息,结果会有所不同 - 因为 OOM 非常努力地将所有签名/加密的消息表示为常规邮件项目,GetRDOObjectFromOutlookObject
将生成未签名/解密的消息,而 GetMessageFromId
将消息处理为它存储在父消息存储中,生成的 MSG 文件将以原始形式存储消息 - 签名/加密。我突然想到(用 VBA):
set Application = CreateObject("Outlook.Application.16")
set item = Application.ActiveExplorer.Selection(1)
'item.SaveAs "c:\temp\signed.msg", olMsgUnicode
set rSession = CreateObject("Redemption.RDOSession")
rSession.MAPIOBJECT = Application.Session.MAPIOBJECT
set rItem = rSession.GetRDOObjectFromOutlookObject(item)
rItem.SaveAs "c:\temp\unsigned.msg", olMsgUnicode
set rItem = rSession.GetMessageFromID(item.EntryID)
rItem.SaveAs "c:\temp\signed.msg", olMsgUnicode