Mapi在我的应用程序下打开默认邮件客户端

Mapi opening default mail client under my application

我正在使用 Mapi 功能从我的应用程序发送电子邮件。 我想要做的是显示默认邮件客户端的新 window。

它起作用了——它打开一个新的 window 并定义了新邮件(包括所有附件等)。

问题是在某些机器上,它不会在我的应用程序之上打开。 它在我的应用程序下打开,有点混乱。 我的代码如下所示:

导入函数:

 [DllImport("MAPI32.DLL")]
    static extern int MAPISendMail(IntPtr sess, IntPtr hwnd, MapiMessage message, int flg, int rsv);

MapiMessage class:

public class MapiMessage
{
    public int reserved;
    public string subject;
    public string noteText;
    public string messageType;
    public string dateReceived;
    public string conversationID;
    public int flags;
    public IntPtr originator;
    public int receipCount;
    public IntPtr receips;
    public int fileCount;
    public IntPtr files;
}

发送邮件功能(核心):

 protected int SendMail(string strSubject, string strBody, int how)
    {
        m_MapiMessage = new MapiMessage();
        m_MapiMessage.subject = strSubject;
        m_MapiMessage.noteText = strBody;

        m_MapiMessage.receips = GetRecipients(out m_MapiMessage.receipCount);
        m_MapiMessage.files = GetAttachments(out m_MapiMessage.fileCount);

        m_lastError = MAPISendMail(new IntPtr(0), new IntPtr(0), m_MapiMessage, how, 0);
        return m_lastError;
    }

发送电子邮件功能(UI):

public int SendMailPopup(string strSubject, string strBody)
    {
        return SendMail(strSubject, strBody, MAPI_LOGON_UI | MAPI_DIALOG);
    }

上面用到的常量是:

   const int MAPI_LOGON_UI = 0x00000001;
    const int MAPI_DIALOG = 0x00000008;

我试过用以下方式设置我的表格:

TopMost=false;

但是没用。

任何想法,为什么在某些机器上行为不同(每台机器都更新了 windows 10)?

也许 Mapi 中有一些标志导致了这种行为?

您需要指定父 window 句柄。以下是 MSDN 对 MAPISendMail 函数的第二个参数的说明:

If the value of the ulUIParam parameter is zero and a dialog box is displayed, the dialog box is application modal. If the ulUIParam parameter contains a parent window handle, it is of type HWND (cast to a ULONG_PTR). If no dialog box is displayed during the call, ulUIParam is ignored.