C++ SimpleMAPI SendMail 总是失败?
我正在尝试使用 SimpleMAPI 来显示在 Vista SP1 上使用 Windows Mail 或 Thunderbird 在 C++ 应用程序 (Borland C++ Builder 2006) 中与附件进行“写消息”对话。 我应该能够使用 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)。 我究竟做错了什么?
提前谢谢了。
I am trying to use SimpleMAPI to display a 'write message' dialogue with an attachment on Vista SP1 with either Windows Mail or Thunderbird in a C++ app (Borland C++ Builder 2006). I should be able to use MAPISendMail to do this.
I don't fill in a recipient address as I expect the user to do that when the mail client displays a 'write message' dialog. I also don't fill in an originator address as I expect the mail client to use the default. I have tried hardcoding them to see if thats the problem and it is not.
My code looks like this:
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
}
It always fails with error code 2 (MAPI_E_FAILURE). What am I doing wrong?
Many thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可能对此感兴趣:
http://groups.google.com/group/microsoft.public.win32.programmer.messaging/browse_thread/thread/a601e68b95f20609/f0b0d80c99d4eba7?lnk=gst&q=Vista+Outlook +2007#f0b0d80c99d4eba7
您是否在关闭电子邮件客户端的情况下尝试过该代码?
This might interest you:
http://groups.google.com/group/microsoft.public.win32.programmer.messaging/browse_thread/thread/a601e68b95f20609/f0b0d80c99d4eba7?lnk=gst&q=Vista+Outlook+2007#f0b0d80c99d4eba7
Have you tried the code with your email client closed?
在 Delphi 中使用类似的方法,发现它不能在线程内部工作。 (Delphi TThread 组件)我使用了完全相同的代码,并且从线程内调用总是失败,即使我使用了同步
Using similar in Delphi and discovered that it does not work from inside a thread. (Delphi TThread component) I used the exact same code and call from within the thread always failed, even though I used synchronize
尝试分配 lpRecips 并将其 lpszAddress 设置为“SMTP:”
Try assinging lpRecips and set it's lpszAddress to "SMTP:"
您必须首先登录到 MAPI 会话
,然后才能调用 SendMail()。 之后,您必须再次注销:
You have to first logon to the MAPI session
then, you can call SendMail(). And after that, you have to logoff again: