MAPI problem

From: Ray (rlewis_at_beeb.net)
Date: 11/22/04


Date: Mon, 22 Nov 2004 20:35:32 -0000

Hi

How do you set the address in MAPI. The code below sends the message to SMTP
server ok with the correct subject and text, but I can't quite figure out
how to get the address right.

public void DoMail(String addr,String msg, String subj)
{
MapiMessage message=new MapiMessage();
MapiRecipDesc recipDesc =new MapiRecipDesc();
message.lpOriginator=recipDesc.lpEntryID;
message.lpszNoteText=msg;
message.lpszSubject=subj;
recipDesc.lpszAddress=addr;
MAPISendMail (IntPtr.Zero, IntPtr.Zero, message, MAPI_LOGON_UI, 0);
}
I guess that the problem is with the line
message.lpOriginator=recipDesc.lpEntryID;

I am doing the following declarations:

public const uint MAPI_LOGON_UI = 0x00000001;
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public class MapiMessage
{
public uint ulReserved = 0;
public string lpszSubject = string.Empty;
public string lpszNoteText = string.Empty;
public string lpszMessageType = null;
public string lpszDateReceived = DateTime.Now.ToString("yyyy/MM/dd hh:mm");
public string lpszConversationID = string.Empty;
public uint flFlags = 0;
public IntPtr lpOriginator = IntPtr.Zero;
public uint nRecipCount = 0;
public IntPtr lpRecips = IntPtr.Zero;
public uint nFileCount = 0;
public IntPtr lpFiles = IntPtr.Zero;
}

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public class MapiRecipDesc
{
public uint ulReserved = 0;
public uint ulRecipClass = MAPI_ORIG;
public string lpszName = string.Empty;
public string lpszAddress = string.Empty;
public uint ulEIDSize = 0;
 public IntPtr lpEntryID = IntPtr.Zero;
}

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

Ray



Relevant Pages

  • Re: Arrays in structures
    ... public uint dwFileAttributes; ... public FILETIME ftLastAccessTime; ... public string cAlternateFileName; ... public struct FILETIME ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: DllImport and Structures - spidermonkey
    ... public string filename; ... public uint lineno; ... public static void ErrorReporter(IntPtr cx, string message, JSErrorReport ... [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Get the RasGetProjectionInfo() to work in C#
    ... public uint dwError; ... public string szServerIpAddress; ... Regards, ... > public class RASPPPIP ...
    (microsoft.public.dotnet.framework.interop)
  • DCOM across domains
    ... public IntPtr pIID; ... public struct COAUTHIDENTITY ... public uint DomainLength; ...
    (microsoft.public.dotnet.framework.interop)
  • Manipulating win32 app menus from c# using pinvoke...
    ... supplying the fMask of the MENUITEMINFO with the MF_OWNERDRAW constant from ... public uint cbSize; ... public IntPtr hbmpChecked; ... private static extern IntPtr GetSubMenu ...
    (microsoft.public.dotnet.languages.csharp)