CMailMessage::FindAttachment Method  
 
INT FindAttachment(
  LPCTSTR lpszFileName  
);

The FindAttachment method searches the message for an attachment with the specified file name.

Parameters

lpszFileName
Pointer to a string that specifies the name of the file attachment to search for. This parameter should only specify a base file name; it should not include a file path and cannot be NULL.

Return Value

If the method succeeds, the return value is the message part number that contains an attachment that matches the specified file name. If the message does not contain an attachment with the specified file name, the method will return MIME_ERROR. To get extended error information, call GetLastError.

Remarks

This method will search the message for a attachment that matches the specified file name. The search is not case-sensitive, however it must match the attachment file name completely. This method will not match partial file names or names that include wildcard characters. To obtain a list of all of the files attached to a message, use the EnumAttachments method.

Example

// The name of the file attachment to search for
LPCTSTR lpszFileName = _T("MyProject.docx");

// Search for the attached file and store it on the local system
INT nMessagePart = pMessage->FindAttachment(lpszFileName);
if (nMessagePart != MIME_ERROR)
{
    pMessage->SetPart(nMessagePart);

    if (pMessage->ExtractFile(lpszFileName) != MIME_ERROR)
        _tprintf(_T("Saved file attachment %s\n"), lpszFileName);
    else
    {
        _tprintf(_T("Unable to save file attachment %s\n"), lpszFileName);
        return;
    }
}

Requirements

Minimum Desktop Platform: Windows 7 (Service Pack 1)
Minimum Server Platform: Windows Server 2008 R2 (Service Pack 1)
Header File: cstools10.h
Import Library: csmsgv10.lib
Unicode: Implemented as Unicode and ANSI versions.

See Also

AttachFile, ExtractAllFiles, ExtractFile, GetAttachedFileName