您目前已離線,請等候您的網際網路重新連線

資訊: 將郵件儲存到 MSG 複合檔案

重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,而非使用人工翻譯而成。Microsoft 同時提供使用者人工翻譯及機器翻譯兩個版本的文章,讓使用者可以依其使用語言使用知識庫中的所有文章。但是,機器翻譯的文章可能不盡完美。這些文章中也可能出現拼字、語意或文法上的錯誤,就像外國人在使用本國語言時可能發生的錯誤。Microsoft 不為內容的翻譯錯誤或客戶對該內容的使用所產生的任何錯誤或損害負責。Microsoft也同時將不斷地就機器翻譯軟體進行更新。

按一下這裡查看此文章的英文版本:171907
結論
本文包含程式碼,示範如何將訊息儲存至複合文件--特別.msg 檔案--是可以讀取任何用戶端支援.msg 檔案格式。
其他相關資訊
下列函式可接受為 in 參數的有效的訊息物件,並使用其屬性建立訊息的複本,並將它儲存到使用.msg 格式是複合檔案。訊息的主旨列是用來當做新檔案的檔案名稱。

注意: In 參數之這個函式的主旨行中的特殊字元可能會造成未預期的結果。程式碼可以寫入以避免在主旨行中的特殊字元,同時不 germane 至主題,而且這類程式碼故意省略
#define INITGUID#include <objbase.h>#define USES_IID_IMessage#include <mapix.h>#include <mapitags.h>#include <mapidefs.h>#include <mapiutil.h>#include <mapiguid.h>#include <imessage.h>// {00020D0B-0000-0000-C000-000000000046}DEFINE_GUID(CLSID_MailMessage,0x00020D0B,0x0000, 0x0000, 0xC0, 0x00, 0x0, 0x00, 0x0, 0x00, 0x00, 0x46);HRESULT SaveToMSG ( LPMESSAGE pMessage ){    HRESULT hRes = S_OK;    LPSPropValue pSubject = NULL;    LPSTORAGE pStorage = NULL;    LPMSGSESS pMsgSession =  NULL;    LPMESSAGE pIMsg = NULL;    SizedSPropTagArray ( 7, excludeTags );    char szPath[_MAX_PATH];    char strAttachmentFile[_MAX_PATH];    LPWSTR lpWideCharStr = NULL;    ULONG cbStrSize = 0L;    // create the file name in the directory where "TMP" is defined    // with subject as the filename and ".msg" extension.    // get temp file directory    GetTempPath(_MAX_PATH, szPath);    // get subject line of message to copy. This will be used as the    // new file name.    HrGetOneProp( pMessage, PR_SUBJECT, &pSubject );    // fuse path, subject, and suffix into one string    strcpy ( strAttachmentFile, szPath );    strcat ( strAttachmentFile, pSubject->Value.lpszA  );    strcat ( strAttachmentFile, ".msg");    // get memory allocation function    LPMALLOC pMalloc = MAPIGetDefaultMalloc();    // Convert new file name to WideChar    cbStrSize = MultiByteToWideChar (CP_ACP,                                     MB_PRECOMPOSED,                                     strAttachmentFile,                                     -1, lpWideCharStr, 0);    MAPIAllocateBuffer ( cbStrSize * sizeof(WCHAR),                            (LPVOID *)&lpWideCharStr );    MultiByteToWideChar (CP_ACP,                         MB_PRECOMPOSED,                         strAttachmentFile,                         -1, lpWideCharStr, cbStrSize );    // create compound file    hRes = ::StgCreateDocfile(lpWideCharStr,                              STGM_READWRITE |                              STGM_TRANSACTED |                              STGM_CREATE, 0, &pStorage);    // Open an IMessage session.    hRes = ::OpenIMsgSession(pMalloc, 0, &pMsgSession);    // Open an IMessage interface on an IStorage object    hRes = ::OpenIMsgOnIStg(pMsgSession,                            MAPIAllocateBuffer,                            MAPIAllocateMore,                            MAPIFreeBuffer,                            pMalloc,                            NULL,                            pStorage,                            NULL, 0, 0, &pIMsg);    // write the CLSID to the IStorage instance - pStorage. This will    // only work with clients that support this compound document type    // as the storage medium. If the client does not support    // CLSID_MailMessage as the compound document, you will have to use    // the CLSID that it does support.    hRes = WriteClassStg(pStorage, CLSID_MailMessage );    // Specify properties to exclude in the copy operation. These are    // the properties that Exchange excludes to save bits and time.    // Should not be necessary to exclude these, but speeds the process    // when a lot of messages are being copied.    excludeTags.cValues = 7;    excludeTags.aulPropTag[0] = PR_ACCESS;    excludeTags.aulPropTag[1] = PR_BODY;    excludeTags.aulPropTag[2] = PR_RTF_SYNC_BODY_COUNT;    excludeTags.aulPropTag[3] = PR_RTF_SYNC_BODY_CRC;    excludeTags.aulPropTag[4] = PR_RTF_SYNC_BODY_TAG;    excludeTags.aulPropTag[5] = PR_RTF_SYNC_PREFIX_COUNT;    excludeTags.aulPropTag[6] = PR_RTF_SYNC_TRAILING_COUNT;    // copy message properties to IMessage object opened on top of    // IStorage.    hRes = pMessage->CopyTo(0, NULL,                            (LPSPropTagArray)&excludeTags,                            NULL, NULL,                            (LPIID)&IID_IMessage,                            pIMsg, 0, NULL );    // save changes to IMessage object.    pIMsg -> SaveChanges ( KEEP_OPEN_READWRITE );    // save changes in storage of new doc file    hRes = pStorage -> Commit(STGC_DEFAULT);    // free objects and clean up memory    MAPIFreeBuffer ( lpWideCharStr );    pStorage->Release();    pIMsg->Release();    CloseIMsgSession ( pMsgSession );    pStorage = NULL;    pIMsg = NULL;    pMsgSession = NULL;    lpWideCharStr = NULL;    return hRes;}				
Outlook 和 Exchange 用戶端的所有版本都支援 CLSID_MailMessage 為複合文件。使用不同的 CLSID 唯一的理由,就是支援當您將訊息寫入結構化儲存體時,請使用不同 CLISD 其他用戶端。

當儲存有大量的收件者或附件的郵件,有可能 CopyTo 作業將失敗,MAPI_E_NOT_ENOUGH_MEMORY。這是由於已知的問題與結構化儲存體和資料流。新的附件或收件者是每次新增郵件儲存在結構化儲存體開啟新的根儲存體檔案。未關閉這些檔案,直到交易完成為止。因為作業系統對於加上同時開啟的根儲存的檔案數目限制,沒有任何已知的解決方法。如需詳細資訊按一下面的文件編號,檢視 「 Microsoft 知識庫 」 中的發行項:
163202Simultaeously 開啟根存放區檔案數目限制
這項限制會影響所有的 Outlook 版本。

警告:本文為自動翻譯

內容

文章識別碼:171907 - 最後檢閱時間:08/18/2005 18:00:56 - 修訂: 2.5

Microsoft Office Outlook 2007, Microsoft Messaging Application Programming Interface, Microsoft Exchange Client 5.5, Microsoft Exchange Client 5.0, Microsoft Exchange Client 4.0, Microsoft Exchange Client 5.0

  • kbmt kbinfo kbmsg KB171907 KbMtzh
意見反應
eateElement('meta');m.name='ms.dqp0';m.content='true';document.getElementsByTagName('head')[0].appendChild(m);" onload="var m=document.createElement('meta');m.name='ms.dqp0';m.content='false';document.getElementsByTagName('head')[0].appendChild(m);" src="http://c1.microsoft.com/c.gif?">