Hello,
I have developed an Outlook Add-in application for sending an email with Zipped attachment file using MAPI lib.I was successful in attaching the files to the outlook email.But when i attach a file in the reply dialog(i.e for the replying the message) using my add-in application its not attaching to the reply dialog and a new email window is started and file is attaching to that email window.Below is the code that i use for attaching the file to outlook.Kindly help me what changes should i do to attach the file to the particular reply message window.
bool SendMail(HWND hWndParent, CString strAttachmentFileName, CString strSubject, CString File)
{
if (strAttachmentFileName.IsEmpty())
{
ErrorFlag = false;
return false;
}
if (!hWndParent || !::IsWindow(hWndParent))
{
ErrorFlag = false;
return false;
}
HINSTANCE hMAPI = ::LoadLibraryA(("MAPI32.DLL"));
if (!hMAPI)
{
ErrorFlag = false;
return false;
}
ULONG (PASCAL *SendMail)(ULONG, ULONG_PTR, MapiMessage*, FLAGS, ULONG);
(FARPROC&)SendMail = GetProcAddress(hMAPI,("MAPISendMail"));
if (!SendMail)
{
ErrorFlag = false;
return false;
}
char szFileName[_MAX_PATH];
char szPath[_MAX_PATH];
char szSubject[_MAX_PATH];
CString FileName = L"";
CString FilePath = L"";
CString FileSubject = L"";
FileName = File;
FilePath = strAttachmentFileName;
FileSubject = strSubject;
sprintf_s(szFileName,"%s",(CT2CA)FileName);
sprintf_s(szPath,"%s",(CT2CA)FilePath);
sprintf_s(szSubject,"%s",(CT2CA)FileSubject);
MapiFileDesc fileDesc;
::ZeroMemory(&fileDesc, sizeof(fileDesc));
fileDesc.nPosition = (ULONG)-1;
fileDesc.lpszPathName = szPath;
fileDesc.lpszFileName = szFileName;
MapiMessage message;
::ZeroMemory(&message, sizeof(message));
message.lpszSubject = szSubject;
message.nFileCount = 1;
message.lpFiles = &fileDesc;
int nError = SendMail(0, (ULONG_PTR)hWndParent, &message, MAPI_DIALOG|MAPI_LOGON_UI, 0);
if (nError != SUCCESS_SUCCESS && nError != MAPI_USER_ABORT && nError != MAPI_E_LOGIN_FAILURE)
{
AfxMessageBox(L"Attachment Error");
ErrorFlag = false;
return false;
}
return true;
}