C++ WIN32 email per Outlook senden WinCE5

HansJ

Mitglied
Hallo,
ich möchte von einem Windows Mobil Pocket PC emails mit einer Datei als Anhang über Outlook versenden.

Ein Beispiel Programm habe ich bei Microsoft gefunden, aber in diesem Beispiel wird eine dummy Datei erzeugt und versendet. Leider habe ich es nicht geschafft eine Datei zu versenden die z.B. in \\Application\\test.txt zur Verfügung steht.
Hier der Code Bereich in dem die Datei erzeugt wird.
Es wäre toll wenn mir jemand helfen könnte.

Code:
// **************************************************************************
// Function Name: CEMAPI_AttachFile
// Purpose: Attaches a bogus file to the outgoing message

// Arguments:
// INOUT LPMESSAGE pmsg - pointer to IMessage interface
//
// Return Values:
//    HRESULT
//    returns S_OK if the "file" is successfully attached, otherwise an error is returned
// 
// Description:  
//
//	This function sets up a file attachment and associates it with the specified message,
//	and reads in the file data from via IStream. The "file" in this example is just dummy 
//  data. Normally data from a real file would be streamed in and written to the attachment. 

HRESULT CEMAPI_AttachFile(
    LPMESSAGE pmsg
    )
{
	IAttach * pAttachment = NULL;
	SPropValue rgpropsAttch[3];
	ULONG ulAttachNum;
	HRESULT hr;
	// bogus filename...normally would reference a real file
	WCHAR wcsAttachmentName[] = L"test.txt";
	DWORD dwFileSize;
	ULONG ulStatus = MSGSTATUS_RECTYPE_SMTP;
	IStream * pstmAttachment = NULL;
	// our fake file data, normally would be streamed in from a file
	char szBuf[] = "Hello, Windows CE";
	
	
	dwFileSize = strlen(szBuf)+1;
	// create the attachment
    hr = pmsg->CreateAttach(NULL, 0, &ulAttachNum, &pAttachment);
    EXIT_ON_FAILED(hr);
 
    rgpropsAttch[0].ulPropTag    =   PR_ATTACH_FILENAME;
    rgpropsAttch[0].Value.lpszW  =   wcsAttachmentName;
 
    rgpropsAttch[1].ulPropTag    =   PR_ATTACH_SIZE;
    rgpropsAttch[1].Value.ul     =   dwFileSize;
 
    rgpropsAttch[2].ulPropTag    =   PR_MSG_STATUS;
    rgpropsAttch[2].Value.ul     =   ulStatus;
 
    hr = pAttachment->SetProps(sizeof(rgpropsAttch)/ sizeof(rgpropsAttch[0]), rgpropsAttch, NULL);
    EXIT_ON_FAILED(hr);
 
    // open a stream on the attachment
    hr = pAttachment->OpenProperty(PR_ATTACH_DATA_BIN, NULL /*&IID_IStream*/, STGM_WRITE, MAPI_MODIFY,
                                    reinterpret_cast <IUnknown **>(&pstmAttachment));
    EXIT_ON_FAILED(hr);

    // store chunk from our fake file buffer into the stream
    hr = pstmAttachment->Write(szBuf, 5, NULL);
    EXIT_ON_FAILED(hr);

    // commit it
    hr = pstmAttachment->Commit(STGC_DEFAULT);
    EXIT_ON_FAILED(hr);

   
FuncExit:	
	RELEASE_OBJ(pAttachment);
	RELEASE_OBJ(pstmAttachment);
	return hr;

}
 
Zurück