This question类似,但未显示如何添加收件人。
我该怎么做?
我们希望尽可能多的Windows平台(来自XP及更高版本)提供最广泛的支持
我们正在使用visual studio 2008
基本上我们想发送一封电子邮件:
从我们的程序中,让用户能够添加任何信息或取消它。
EDIT 我正在尝试使用MAPISendMail() 我从顶部附近链接的问题中复制了大部分代码,但是我没有收到电子邮件dlg框并且我从调用中获得的错误返回是:0x000f - “系统找不到指定的驱动器”
如果我注释掉设置收件人的行,它可以正常工作(当然我没有预先填写的收件人)
以下是代码:
#include <tchar.h>
#include <windows.h>
#include <mapi.h>
#include <mapix.h>
int _tmain( int argc, wchar_t *argv[] )
{
HMODULE hMapiModule = LoadLibrary( _T( "mapi32.dll" ) );
if ( hMapiModule != NULL )
{
LPMAPIINITIALIZE lpfnMAPIInitialize = NULL;
LPMAPIUNINITIALIZE lpfnMAPIUninitialize = NULL;
LPMAPILOGONEX lpfnMAPILogonEx = NULL;
LPMAPISENDDOCUMENTS lpfnMAPISendDocuments = NULL;
LPMAPISESSION lplhSession = NULL;
LPMAPISENDMAIL lpfnMAPISendMail = NULL;
lpfnMAPIInitialize = (LPMAPIINITIALIZE)GetProcAddress( hMapiModule, "MAPIInitialize" );
lpfnMAPIUninitialize = (LPMAPIUNINITIALIZE)GetProcAddress( hMapiModule, "MAPIUninitialize" );
lpfnMAPILogonEx = (LPMAPILOGONEX)GetProcAddress( hMapiModule, "MAPILogonEx" );
lpfnMAPISendDocuments = (LPMAPISENDDOCUMENTS)GetProcAddress( hMapiModule, "MAPISendDocuments" );
lpfnMAPISendMail = (LPMAPISENDMAIL)GetProcAddress( hMapiModule, "MAPISendMail" );
if ( lpfnMAPIInitialize && lpfnMAPIUninitialize && lpfnMAPILogonEx && lpfnMAPISendDocuments )
{
HRESULT hr = (*lpfnMAPIInitialize)( NULL );
if ( SUCCEEDED( hr ) )
{
hr = (*lpfnMAPILogonEx)( 0, NULL, NULL, MAPI_EXTENDED | MAPI_USE_DEFAULT, &lplhSession );
if ( SUCCEEDED( hr ) )
{
// this opens the email client
// create the msg. We need to add recipients AND subject AND the dmp file
// file attachment
MapiFileDesc filedesc;
::ZeroMemory(&filedesc, sizeof(filedesc));
filedesc.nPosition = (ULONG)-1;
filedesc.lpszPathName = "E:\\Development\\Open\\testmail\\testmail.cpp";
// recipient(s)
MapiRecipDesc recip;
::ZeroMemory(&recip, sizeof(recip));
recip.lpszName = "QA email";
recip.lpszAddress = "qa@myaccount.com";
// the message
MapiMessage msg;
::ZeroMemory(&msg, sizeof(msg));
msg.lpszSubject = "Test";
msg.nRecipCount = 1; // if I comment out this line it works fine...
msg.lpRecips = &recip;
msg.nFileCount = 1;
msg.lpFiles = &filedesc;
hr = (*lpfnMAPISendMail)(0, NULL, &msg, MAPI_LOGON_UI|MAPI_DIALOG, 0);
if ( SUCCEEDED( hr ) )
{
hr = lplhSession->Logoff( 0, 0, 0 );
hr = lplhSession->Release();
lplhSession = NULL;
}
}
}
(*lpfnMAPIUninitialize)();
}
FreeLibrary( hMapiModule );
}
return 0;
}
答案 0 :(得分:2)
哎呀 - 我忘了设置
recip.ulRecipClass = MAPI_TO;
现在很棒。