views:

489

answers:

3

Microsoft Word has "send as attachment" functionality which creates a new message in Outlook with the document attached.

I would like to replace Outlook with a custom mail agent, but I do not know how to achieve this. Now my mail agent is simply a program that runs, and takes a file name as parameter.

As far as I know, "send as attachment" is using some DLL/API called MAPI. I would need to change my app so that it does not simply accept file name arguments, but can receive MAPI(?) calls MS Word uses when "sending as attachment".

Further, I need to change the default mail agent by creating my own MAPI32.dll stub which simply redirects to my app.

I'd appreciate if anyone had more info on how this could be achieved!

A: 

OK, to answer my own question. I need to build a DLL with "MAPISendDocuments" and/or "MAPISendMail" functions defined.

This DLL can have any name, and is referenced in the registry at HKLM/Software/Clients/Mail/MyMailApp/DLLPath.

Found examples using Delphi...

goorj
A: 

I need to achieve the same solution, did you manage to code your own DLL? If so, any chance of posting the code?

Andy Groom
I have not had time yet. The interface is well documented, but as I am not familiar with WIN/DLL coding, I need to spend some time getting to know the basics. Someone with more knowledge could probable create a stub DLL in 2 minutes!
goorj
+1  A: 

When writing your own mapi implementation it is critical to create a dll with both the proper exports and calling conventions in order for the system stub mapi dll (c:\windows\system32\mapi32.dll, should be the same as mapistub.dll) to pass calls through to your dll. MAPI functions are called with the __stdcall calling convention. Also critical is setting the right registry keys in order for you mapi dll to be chosen by the system stub, it looks like you've already found the right one in order to specify a particular mapi dll be used when your applicaion makes mapi calls.

I did this exact thing just recently: wrote my own skeleton mapi dll, and had a lot of trouble getting the system stub to call my extended mapi functions. The key was that mapi32.dll calls GetProcAddress on the "foo@x" entry point, not the "foo" entrypoint in the mapi interface in order to test whether or not your dll is "compliant" with extended mapi (I think for simple mapi calls it does not use the "foo@x" but the plain "foo" entrypoint name). I also had to compile my skeleton library interface file in my project "As C" and not "As C++" in order to get all the symbol names right.

For example, MAPIInitialize should be declared like this in your source code:

HRESULT __stdcall MAPIInitialize( LPVOID lpMapiInit )
...

and you'll need to specify a .def file with entries like this:

EXPORTS
    MAPIInitialize@4=_MAPIInitialize@4
    MAPIInitialize=_MAPIInitialize@4

For simple mapi calls (as opposed to extended mapi calls), you may not need the "double export". In order to see what the exports look like for a working mapi implementation, you can do this (if you have outlook installed on your system):

c:\> dumpbin /exports c:\Program Files\Common Files\SYSTEM\MSMAPI\1033\msmapi32.dll

(or substitute the path you find in the registry in HKLM\Software\Clients\Mail\Microsoft Outlook\DLLPathEx)

Bogatyr