我正在尝试使用SimpleMAPI在 C++ 应用程序(Borland C++ Builder 2006)中使用 Windows Mail 或 Thunderbird 在 Vista SP1 上显示带有附件的“写消息”对话框。我应该能够使用MAPISendMail来执行此操作。
我没有填写收件人地址,因为我希望用户在邮件客户端显示“写消息”对话框时这样做。我也没有填写发起人地址,因为我希望邮件客户端使用默认值。我已经尝试对它们进行硬编码,看看是否是问题所在,而事实并非如此。
我的代码如下所示:
HINSTANCE hMAPI;
LPMAPISENDMAIL pSendMail;
MapiMessage message;
MapiFileDesc file;
ZeroMemory( &message, sizeof( MapiMessage ) );
ZeroMemory( &file, sizeof( MapiFileDesc ) );
hMAPI = LoadLibraryA( "MAPI32.DLL" );
pSendMail = (LPMAPISENDMAIL)GetProcAddress( hMAPI, "MAPISendMail" );
// setup the attachment...
file.nPosition = -1;
file.lpszPathName = "C:\\my_attachment.dat";
// set up the message...
message.lpszSubject = "My Subject";
message.lpszNoteText = "My Message...";
message.lpszMessageType = "";
message.nRecipCount = 0;
message.lpRecips = NULL; // we don't know the recipient address(s)
message.nFileCount = 1;
message.lpFiles = &file;
message.lpOriginator = NULL; // we don't know the users from address
dwResult = pSendMail( lhSessionNull, (DWORD)Application->Handle, &message, MAPI_LOGON_UI | MAPI_DIALOG, 0 );
if( dwResult == SUCCESS_SUCCESS )
{
// ...yay! :)
}
else
{
// ...we always fail here with: MAPI_E_FAILURE
}
它总是以错误代码 2 (MAPI_E_FAILURE) 失败。我究竟做错了什么?
提前谢谢了。