Home All Groups Group Topic Archive Search About

Opening Mailclient with MAPI

Author
24 Apr 2007 1:41 PM
Christof Nordiek
From my application, informations can be sendt by the user. Until now I'm
using
Process.Start("mailto:....)
This works very fine, but I get problems, when the preset content is to
much, because the length of the URL is restricted.
IIRC this also can be solved by MAPI, but I can't find any example how to do
this with C#.

Is this really possible and can anyone give me a hint, how to do this?

thanks
Christof

Author
25 Apr 2007 9:30 AM
Christof Nordiek
It seems that I can use MAPISendMail from the mapi32.dll
Following Code works well so far:

   MapiMessage message = new MapiMessage();
   message.lpszSubject = "Nachricht mit Text";
   message.lpszNoteText = "Dieser Text wird gesendet.";
   uint err = MAPISendMail(IntPtr.Zero, IntPtr.Zero, message, 8, 0);

The declarations for MapiMessage and MAPISendMail are below.
There are two problems.

1. I can't figure out, how to preset the to field (and maybe other
adressfields.)
The MapiMessage has a lpRecips field, wich is an pointer to an array of
MapiRecipDesc structure.
There is also a definition for the MapiRecipDesc structure in PInvoke.net,
but I can't put it all together.

The lpRecips field is of type IntPtr, but I can't get an IntPtr pointing to
an array of MapiRecipDesc instances. Changing the type of lpRecips to an
array doesn't work.
Does anyone know how to do it?

2. The Mailclient.Dialog is modal and so blocks the UI. Can this be
prevented?

Followin the declarations of MAPISendMail and MapiMessage:

  [DllImport("MAPI32.DLL", CharSet=CharSet.Ansi)]
  public static extern uint MAPISendMail(IntPtr lhSession, IntPtr ulUIParam,
   MapiMessage lpMessage, uint flFlags, uint ulReserved);

  /// <summary>
  /// A MapiMessage structure contains information about a message.
  /// </summary>
  [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
  public class MapiMessage
  {
   /// <summary>
   /// Reserved; must be zero.
   /// </summary>
   public uint ulReserved = 0;

   /// <summary>
   /// Pointer to the text string describing the message subject,
   /// typically limited to 256 characters or less.
   ///
   /// If this member is empty or NULL, the user has not entered subject
text.
   /// </summary>
   public string lpszSubject = string.Empty;

   /// <summary>
   /// Pointer to a string containing the message text.
   ///
   /// If this member is empty or NULL, there is no message text.
   /// </summary>
   public string lpszNoteText = string.Empty;

   /// <summary>
   /// Pointer to a string indicating a non-IPM type of message.
   ///
   /// Client applications can select message types for their non-IPM
messages.
   ///
   /// Clients that only support IPM messages can ignore the lpszMessageType
member
   /// when reading messages and set it to empty or NULL when sending
messages.
   /// </summary>
   public string lpszMessageType = null;

   /// <summary>
   /// Pointer to a string indicating the date when the message was
received.
   ///
   /// The format is YYYY/MM/DD HH:MM, using a 24-hour clock.
   /// </summary>
   public string lpszDateReceived = DateTime.Now.ToString("yyyy/MM/dd
hh:mm");

   /// <summary>
   /// Pointer to a string identifying the conversation thread to which the
message belongs.
   ///
   /// Some messaging systems can ignore and not return this member.
   /// </summary>
   public string lpszConversationID = string.Empty;

   /// <summary>
   /// Bitmask of message status flags.
   ///
   /// The flags are MAPI_RECEIPT_REQUESTED , MAPI_SENT,
   /// and MAPI_UNREAD.
   /// </summary>
   public uint flFlags = 0;

   /// <summary>
   /// Pointer to a MapiRecipDesc structure containing information about the
   /// sender of the message.
   /// </summary>
   public IntPtr lpOriginator = IntPtr.Zero;

   /// <summary>
   /// The number of message recipient structures in the array pointed to by
the
   /// lpRecips member.
   ///
   /// A value of zero indicates no recipients are included.
   /// </summary>
   public uint nRecipCount = 0;

   /// <summary>
   /// Pointer to an array of MapiRecipDesc structures, each containing
   /// information about a message recipient.
   /// </summary>
   public IntPtr lpRecips;

   /// <summary>
   /// The number of structures describing file attachments in the array
pointed to by the
   /// lpFiles member.
   ///
   /// A value of zero indicates no file attachments are included.
   /// </summary>
   public uint nFileCount = 0;

   /// <summary>
   /// Pointer to an array of MapiFileDesc structures, each containing
   /// information about a file attachment.
   /// </summary>
   public IntPtr lpFiles = IntPtr.Zero;
  }

AddThis Social Bookmark Button