如何使用MAPI将文件文件附加到outlook中的回复对话框 [英] How to attach a file file to the reply dialogue in outlook using MAPI

查看:53
本文介绍了如何使用MAPI将文件文件附加到outlook中的回复对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我开发了一个Outlook加载项应用程序,用于使用MAPI lib发送带有Zipped附件文件的电子邮件。我成功将文件附加到outlook电子邮件。但是当我使用我的加载项应用程序在回复对话框中附加文件(即回复邮件)时,它没有附加到回复对话框,并且启动了新的电子邮件窗口并且文件附加到该电子邮件窗口.Below是我用来将文件附加到outlook的代码.Kindly帮我改变应该将文件附加到特定的回复消息窗口。



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;
}

推荐答案

这篇关于如何使用MAPI将文件文件附加到outlook中的回复对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆