gpt4 book ai didi

c# - 使用 SendMessage 击败 'A program is trying to access email'

转载 作者:行者123 更新时间:2023-11-30 22:32:46 27 4
gpt4 key购买 nike

我正在用 C# 编写一个应用程序,该应用程序使用 Office Outlook Interop(2010;版本 14)通过 MAPI 访问电子邮件数据。

到目前为止,我必须在 Outlook 的“程序正在尝试访问存储在 Outlook 中的电子邮件地址信息”安全弹出窗口中手动重复单击“允许”(屏幕截图位于 http://i.stack.imgur.com/gj8to.png)。

我尝试编写一个方法来自动进行点击,但没有成功。单击发生,但 Outlook Interop 在下一次读取操作期间引发以下异常:

Exception from HRESULT: 0x80004004 (E_ABORT)

下面是一段使用 SendMessage 来点击允许按钮的代码:

private const Int32 BM_CLICK = 0x00F5;
private const Int32 GWL_STYLE = -16;
private const Int32 CB_SETCURSEL = 0x14E;
private const Int32 WM_LBUTTONDOWN = 0x201;
private const Int32 WM_LBUTTONUP = 0x202;

private const string dialogClass = "#32770";
private const string dialogTitle = "Microsoft Outlook";
const string tickBoxTitle = @"&Allow access for";
const string tickBoxClass = @"Button";

private const int ThreadSleepTime = 1000;
private const int ThreadUiSleepTime = 20;

IntPtr popupHandle;
IntPtr tickHandle = IntPtr.Zero;
IntPtr comboHandle = IntPtr.Zero;
IntPtr allowHandle = IntPtr.Zero;
while ((popupHandle = FindWindow(dialogClass, dialogTitle)) != IntPtr.Zero)
{
// Get object handles
tickHandle = FindWindowEx(popupHandle, tickHandle, tickBoxClass, tickBoxTitle);
comboHandle = FindWindowEx(popupHandle, tickHandle, null, null);
allowHandle = FindWindowEx(popupHandle, comboHandle, null, null);

// Click on tickbox until the combobox is enabled
while ((GetWindowLong(comboHandle, GWL_STYLE) & 0x8000000) != 0)
{
SendMessage(tickHandle, BM_CLICK, new IntPtr(1), IntPtr.Zero);
System.Threading.Thread.Sleep(ThreadUiSleepTime);
}

// Set dropdown box selection index to 3rd row
SendMessage(comboHandle, CB_SETCURSEL, 3, 0);
System.Threading.Thread.Sleep(ThreadUiSleepTime);

// Click Allow button
//SendMessage(allowHandle, BM_CLICK, new IntPtr(1), IntPtr.Zero);

SendMessage(allowHandle, WM_LBUTTONDOWN, IntPtr.Zero, new IntPtr(MakeLParam(5, 5)));
System.Threading.Thread.Sleep(ThreadUiSleepTime);
SendMessage(allowHandle, WM_LBUTTONUP, IntPtr.Zero, new IntPtr(MakeLParam(5, 5)));
}

为什么 SendMessage 不起作用,我该如何让它起作用?

最佳答案

您应该使用 EMAPI,它不会显示这些警告。
Redemption library提供了一个方便的包装器。

关于c# - 使用 SendMessage 击败 'A program is trying to access email',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8598596/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com