[Webinar] Streamline your web hosting managementRegister Today


SImple MAPI use of attached files

Posted on 2000-01-17
Medium Priority
Last Modified: 2013-12-03
My question deals with using the Simple MAPI function,
MAPISendMail in Visual C++ 5.0.  Within the MapiMessage struct
there is the following member;
lpMapiFileDesc - Pointer to an array of MapiFileDesc structures,
each containing information about a file attachment.
Within the MapiFileDesc there is the following pointer,
lpFileType - Pointer to the attachment file type,
which can be represented with a MapiFileTagExt structure.  
Within the MapiFileTagExt struct there are the following members;

cbTag - The size, in bytes, of the value defined by the lpTag member.

lpTag - Pointer to an X.400 object identifier indicating the type of the attachment
in its original form, for example "Microsoft Excel worksheet".

cbEncoding - The size, in bytes, of the value defined by the lpEncoding member.

lpEncoding - Pointer to an X.400 object identifier indicating the form in which
the attachment is currently encoded, for example MacBinary, UUENCODE, or binary.

Now my question, where do I find the values/data for the above.
These are X.400 Object IDs or OIDs.  I need an example on for
attaching a standard .txt file that can be viewed in
Notepad.  My attachment is unreadalbe when opened from a browser.
Question by:Cmustaffa
  • 3
  • 2

Expert Comment

ID: 2360029
you look in this file MAPITAGS.H ?

Author Comment

ID: 2360071
Yes, I've looked in MAPITAGS.H.  I think MAPIOID.H contains a few OIDs
but I not sure how to use them.  Those
fields require X.400 OIDs. The OID
fields are defined as LPBYTE and the
lengths as ULONG.  But the length fields
give an example of "Microsoft Excel worksheet", do I get the lenght with this;
char szFileType = "Microsoft Excel..";
ULONG uLength = strlen(szFileType);
LPBYTE pFileType = X.400 OID for Excel?

Expert Comment

ID: 2360732
may be this way?
I find this in msdn

MapiFileTagExt (Simple MAPI)
A MapiFileTagExt structure specifies a message attachment's type at its creation and its current form of encoding so that it can be restored to its original type at its destination.

Quick Info
Header file: MAPI.H

typedef struct {
     ULONG ulReserved;
     ULONG cbTag;
     LPBYTE lpTag;
     ULONG cbEncoding;
     LPBYTE lpEncoding
} MapiFileTagExt, FAR *lpMapiFileTagExt;
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Author Comment

ID: 2362695
You didn't answer the question!  What
are the values that are used in the following fields;
ULONG cbTag;
ULONG cbEncoding;
LPBYTE lpEncoding
LVL 14

Accepted Solution

AlexVirochovsky earned 100 total points
ID: 2371057
Cmustaffa, you don't need X.400 protocol
for usually text file!
Next is an simple example sending mail with attached file:
  HRESULT hRes;// = S_OK;
  ULONG ulReserved = 0L;
  LPSTR lpszFileName = NULL,
  lpszPathName = NULL;
  char   szErr[256];
  char lpszFullPath[256] = {NULL};

  lpMapiRecipDesc pRecips = NULL;
  MapiMessage Message;
  MapiFileDesc pFileDesc;

  ZeroMemory ( &Message, sizeof ( MapiMessage ) );
  ZeroMemory ( &pFileDesc, sizeof ( MapiFileDesc ) );

  if ( m_lhSession )       // Always check to make sure there is an active session
            // Populate members of Message structure.
      char lpszName[255],szSubject[255];

      cResolveName ( lpszName, &pRecips );
      Message.nRecipCount  = 1L; // Must be set to the correct number of recipients.
      pRecips->ulRecipClass = MAPI_TO;
      Message.lpRecips         = pRecips;      // Address of list of names returned from MAPIAddress.

            // Capture the file name and path name. strcat the file name to the end of the
            // path name
      strcat ( lpszFullPath, szDir );
      strcat ( lpszFullPath, szFileName );

            // Set the file and path name members of the MapiFileDesc.
      pFileDesc.lpszFileName = szFileName;
      pFileDesc.lpszPathName = lpszFullPath;

            // Set the other members of the MapiMessage structure.
                  // We only support 1 attachment so nFileCount gets set to 1.
      Message.ulReserved     = ulReserved;
      strcpy(szSubject, "Name");

      Message.lpszSubject    = ( LPTSTR ) szSubject;
      Message.lpszNoteText   = ( LPTSTR ) szMessage;
      Message.lpOriginator   = NULL;
      Message.nFileCount     = 1L;
      Message.lpFiles           = &pFileDesc;

      hRes = m_MAPISendMail (m_lhSession,      // Global session handle.
                       0L,            // Parent window. Set to 0 since console app.
                       &Message,             // Address of Message structure
                       ulReserved);       // Reserved. Must be 0L.

      if ( hRes == SUCCESS_SUCCESS )
I hope, it helps. Alex

Author Comment

ID: 2375034
Alex, I can get the attachment to correctly detach if the recipient is
using MS OutLook, i.e., the attactment
appear as a Notepad icon at the bottom
of the file.  The problem is when I email the attachment with the name;
SMTP:anyname@hotmail.com or anyname@aol.com or to any non-MS mailer
program the attachment appears as "Unknown" file type in aol and detaches
as garbage in hotmail. I think these environments need the X.400 OID tags
to properly decode and detach the .txt
files.  I found the X.400 OIDs on the Internet for Microsoft's file formats
and the mapioid.h contains a few OIDs,
but trying to use the macros to create
an OID BYTE tag generated errors. I \
believe that the MapiFileTagExt struct
is used for non-MS environments, why else would it be included?  Thanks for
P.S. I found nothing on MSDN or KB KB    

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question