Page by E-mail from IE

Please discuss general Delphi programming topics here.

Page by E-mail from IE

Postby Stefan » January 18th, 2011, 4:01 pm

Hi

My app is a simple mail client and has been registered as such in the Windows Registry.
Now, in Internet Explorer there's an option to change the mail-client that is to be used for any mail related actions started from IE.

One of these actions (I suppose) is "Page by E-mail..." under File->Send in the menu.
After setting my mail client as the default mail client (which IE acknowledges in Tools->Options-Programs->E-mail) using the menu option defined above does not work.
The mail client is not even started and there's no error message. Nothing happens (visibly anyway).

I wonder what I need to do to get this to work. Any suggestions?

Stefan
User avatar
Stefan
Moderator
Moderator
 
Posts: 128
Joined: September 27th, 2004, 9:40 am
Location: Tilburg, The Netherlands

Re: Page by E-mail from IE

Postby Kambiz » January 18th, 2011, 11:42 pm

Did you try to set your mail client as the default handler for mailto protocol?
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: Page by E-mail from IE

Postby mathgod » January 19th, 2011, 4:46 am

I think you need an SMTP server specified in a configuration file or hard-coded in an application. I did a lot of research on the topic of sending mail and found no way to send mail from one location to another without involving an SMTP server somewhere between the sending and receiving points. Unlike DNS servers, there are no free or open SMTP servers. Another obstacle may be your service provider blocking port 25 and possibly other "message out" ports.
User avatar
mathgod
Junior Member
Junior Member
 
Posts: 35
Joined: December 15th, 2007, 4:36 pm
Location: Middle of New Mexico, USA

Re: Page by E-mail from IE

Postby Stefan » January 19th, 2011, 11:45 am

The SMTP server is not the issue. The problem is in starting the client.
Registered the app for the mailto protocol in the registry, but I'm not sure I've covered them all.

Now it is registered in:

HKEY_LOCAL_MACHINE\SOFTWARE\mailto\shell\open\command

But perhaps that's just meant for explorer, not internet explorer? (It does work in explorer, by the way)
I found another key at HKEY_CLASSES_ROOT\PROTOCOLS\Handler\mailto with in it a CLSID string which points to some GUID of which I'm not sure it is from my app.

Will check it out and let you know!

Thanks!
User avatar
Stefan
Moderator
Moderator
 
Posts: 128
Joined: September 27th, 2004, 9:40 am
Location: Tilburg, The Netherlands

Re: Page by E-mail from IE

Postby Stefan » January 19th, 2011, 4:17 pm

Strange days...

When in IE, in the address-bar I type: mailto:whatever@somewhere.com it opens my client.
Same thing when I do that from FireFox or from Start-Run; my client starts every time without problems.
This makes me believe that registering my client for the mailto protocol is succesful.

The only thing that does not work is that damned IE menu option.

I did an export of my registry and afterwards set the mail client to Thunderbird (instead of my app) in IE->Tools->Internet Options->Programs->E-mail
Looking at the changes there's only changes to settings my app does aswell, so no new entries that I've failed to register except for some random looking ones (like the registry setting for the RNG and some cache updates for Shell Extensions).

Looking around on the internets, I'm sort of coming to the conclusion that the menu option does not use the mailto: protocol handler, but the default MAPI mail client - which my app is not.

I don't know how to go about this either. Is it easy to implement? Are there any 3rd party components to "quickfix" this?
Anyone have any suggestions?
User avatar
Stefan
Moderator
Moderator
 
Posts: 128
Joined: September 27th, 2004, 9:40 am
Location: Tilburg, The Netherlands

Re: Page by E-mail from IE

Postby Kambiz » January 19th, 2011, 9:41 pm

I'm curious to know whether "Page by E-mail" works, when you set the default mailer to Thunderbird?
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: Page by E-mail from IE

Postby Stefan » January 20th, 2011, 9:01 am

So was I, and yes it does :)
User avatar
Stefan
Moderator
Moderator
 
Posts: 128
Joined: September 27th, 2004, 9:40 am
Location: Tilburg, The Netherlands

Re: Page by E-mail from IE

Postby Stefan » January 20th, 2011, 9:23 am

Good thing I paid such good attention whilst in German class :)

http://www.delphipraxis.net/81206-eigen ... eiben.html
User avatar
Stefan
Moderator
Moderator
 
Posts: 128
Joined: September 27th, 2004, 9:40 am
Location: Tilburg, The Netherlands

Re: Page by E-mail from IE

Postby Stefan » January 20th, 2011, 9:44 am

And it works! Compiled the code

Code: Select all
library LibMAPI;

uses
  SysUtils,
  Windows,
  Classes,
  Dialogs,
  main in 'main.pas';

{$R *.res}

exports MAPILogon name 'MAPILogon';
exports MAPILogoff name 'MAPILogoff';
exports MAPISendMail name 'MAPISendMail';
exports MAPISendDocuments name 'MAPISendDocuments';
exports MAPIFindNext name 'MAPIFindNext';
exports MAPIReadMail name 'MAPIReadMail';
exports MAPISaveMail name 'MAPISaveMail';
exports MAPIDeleteMail name 'MAPIDeleteMail';
exports MAPIFreeBuffer name 'MAPIFreeBuffer';
exports MAPIAddress name 'MAPIAddress';
exports MAPIDetails name 'MAPIDetails';
exports MAPIResolveName name 'MAPIResolveName';
exports GetMapiDllVersion name 'GetMapiDllVersion';

procedure DllMain(reason: integer);
begin
    case reason of
        DLL_PROCESS_ATTACH:
            begin
// ShowMEssage('Attach');
    ExitCode := 0;
            end;
        DLL_PROCESS_DETACH :
            begin
// ShowMEssage('Detach');
    ExitCode := 0;
            end;
    end;
    ExitCode := 0;
end;

begin
    DllProc := @DllMain;
    DllProc(DLL_PROCESS_ATTACH);
end.


and

Code: Select all
unit main;
interface

uses
    Windows
    , Dialogs
    , MAPI
    ;

 
function MAPILogon(ulUIParam: Cardinal; lpszProfileName: LPSTR; lpszPassword: LPSTR; flFlags: FLAGS; ulReserved: Cardinal; lplhSession: PLHANDLE): Cardinal; stdcall;
function MapiLogOff(lhSession: LHANDLE; ulUIParam: Cardinal; flFlags: FLAGS; ulReserved: Cardinal): Cardinal; stdcall;
function MapiSendMail(lhSession: LHANDLE; ulUIParam: Cardinal; var lpMessage: TMapiMessage; flFlags: FLAGS; ulReserved: Cardinal): Cardinal; stdcall;
function MapiSendDocuments(ulUIParam: Cardinal; lpszDelimChar: LPSTR; lpszFilePaths: LPSTR; lpszFileNames: LPSTR; ulReserved: Cardinal): Cardinal;stdcall;
function MapiFindNext(lhSession: LHANDLE; ulUIParam: Cardinal;
        lpszMessageType: LPSTR; lpszSeedMessageID: LPSTR; flFlags: FLAGS;
        ulReserved: Cardinal; lpszMessageID: LPSTR): Cardinal;stdcall;
function MapiReadMail(lhSession: LHANDLE; ulUIParam: Cardinal;
        lpszMessageID: LPSTR; flFlags: FLAGS; ulReserved: Cardinal;
        var lppMessage: PMapiMessage): Cardinal;stdcall;
function MapiSaveMail(lhSession: LHANDLE; ulUIParam: Cardinal;
        var lpMessage: TMapiMessage; flFlags: FLAGS; ulReserved: Cardinal;
        lpszMessageID: LPSTR): Cardinal;stdcall;
function MapiDeleteMail(lhSession: LHANDLE; ulUIParam: Cardinal;
        lpszMessageID: LPSTR; flFlags: FLAGS;
        ulReserved: Cardinal): Cardinal;stdcall;
function MapiFreeBuffer(pv: Pointer): Cardinal;stdcall;
function MapiAddress(lhSession: LHANDLE; ulUIParam: Cardinal;
        lpszCaption: LPSTR; nEditFields: Cardinal; lpszLabels: LPSTR;
        nRecips: Cardinal; var lpRecips: TMapiRecipDesc; flFlags: FLAGS;
        ulReserved: Cardinal; lpnNewRecips: PULONG;
        var lppNewRecips: PMapiRecipDesc): Cardinal; stdcall;
function MapiDetails(lhSession: LHANDLE; ulUIParam: Cardinal;
        var lpRecip: TMapiRecipDesc; flFlags: FLAGS;
        ulReserved: Cardinal): Cardinal; stdcall;
function MapiResolveName(lhSession: LHANDLE; ulUIParam: Cardinal;
        lpszName: LPSTR; flFlags: FLAGS; ulReserved: Cardinal;
        var lppRecip: PMapiRecipDesc): Cardinal; stdcall;
function GetMapiDllVersion : Cardinal; stdcall;

implementation


//******************************************************************************

//******************************************************************************

function GetMapiDllVersion : Cardinal; stdcall;
begin
    MessageBeep(0);

    ShowMessage('GetDLLVersion');
    Result := 97;
end;


function MAPILogon(ulUIParam: Cardinal; lpszProfileName: LPSTR; lpszPassword: LPSTR; flFlags: FLAGS; ulReserved: Cardinal; lplhSession: PLHANDLE): Cardinal; stdcall;
begin
    MessageBeep(0);

    ShowMessage('Logon');
    Result := SUCCESS_SUCCESS
end;

function MapiLogOff(lhSession: LHANDLE; ulUIParam: Cardinal; flFlags: FLAGS; ulReserved: Cardinal): Cardinal; stdcall;
begin
    MessageBeep(0);

    ShowMessage('Logoff');
    Result := SUCCESS_SUCCESS
end;

function MapiSendMail(lhSession: LHANDLE; ulUIParam: Cardinal;
    var lpMessage: TMapiMessage; flFlags: FLAGS; ulReserved: Cardinal): Cardinal; stdcall;
begin
 ShowMessage('SendMail, biatch!');

//    SendMAPIMail(lpMessage);
    Result := 1;
end;

function MapiSendDocuments(ulUIParam: Cardinal; lpszDelimChar: LPSTR;
  lpszFilePaths: LPSTR; lpszFileNames: LPSTR; ulReserved: Cardinal): Cardinal; stdcall;
begin
// MessageBeep(0);

   
    ShowMessage('SendDocuments : Deli : "'+lpszDelimChar+'"'+#13+#10+
        'FilePAth : "'+lpszFilePaths+'"'+#13+#10+
        'lpszFileNames : "'+lpszFileNames+'"'
    );

//    SendMAPIDocuments(lpszDelimChar, lpszFilePaths, lpszFileNames);
    Result := SUCCESS_SUCCESS;
end;

function MapiFindNext(lhSession: LHANDLE; ulUIParam: Cardinal;
  lpszMessageType: LPSTR; lpszSeedMessageID: LPSTR; flFlags: FLAGS;
  ulReserved: Cardinal; lpszMessageID: LPSTR): Cardinal;
begin
    Result := MAPI_E_FAILURE;
end;

function MapiReadMail(lhSession: LHANDLE; ulUIParam: Cardinal;
  lpszMessageID: LPSTR; flFlags: FLAGS; ulReserved: Cardinal;
  var lppMessage: PMapiMessage): Cardinal;
begin
    Result := MAPI_E_FAILURE;
end;

function MapiSaveMail(lhSession: LHANDLE; ulUIParam: Cardinal;
  var lpMessage: TMapiMessage; flFlags: FLAGS; ulReserved: Cardinal;
  lpszMessageID: LPSTR): Cardinal;
begin
    Result := MAPI_E_FAILURE;
end;

function MapiDeleteMail(lhSession: LHANDLE; ulUIParam: Cardinal;
  lpszMessageID: LPSTR; flFlags: FLAGS;
  ulReserved: Cardinal): Cardinal;
begin
    Result := MAPI_E_FAILURE;
end;

function MapiFreeBuffer(pv: Pointer): Cardinal;
begin
    Result := MAPI_E_FAILURE;
end;

function MapiAddress(lhSession: LHANDLE; ulUIParam: Cardinal;
  lpszCaption: LPSTR; nEditFields: Cardinal; lpszLabels: LPSTR;
  nRecips: Cardinal; var lpRecips: TMapiRecipDesc; flFlags: FLAGS;
  ulReserved: Cardinal; lpnNewRecips: PULONG;
  var lppNewRecips: PMapiRecipDesc): Cardinal;
begin
    Result := MAPI_E_FAILURE;
end;

function MapiDetails(lhSession: LHANDLE; ulUIParam: Cardinal;
  var lpRecip: TMapiRecipDesc; flFlags: FLAGS;
  ulReserved: Cardinal): Cardinal;
begin
    Result := MAPI_E_FAILURE;
end;

function MapiResolveName(lhSession: LHANDLE; ulUIParam: Cardinal;
  lpszName: LPSTR; flFlags: FLAGS; ulReserved: Cardinal;
  var lppRecip: PMapiRecipDesc): Cardinal;
begin
    Result := MAPI_E_FAILURE;
end;

end.


And replaced the existing MAPI32.DLL and MAPISTUB.DLL in c:\windows\system32 with the resulting DLL and now I get a little dialog saying 'Sendmail, ...' when I use the IE menu option :)

Thanks for all the help!
User avatar
Stefan
Moderator
Moderator
 
Posts: 128
Joined: September 27th, 2004, 9:40 am
Location: Tilburg, The Netherlands

Re: Page by E-mail from IE

Postby Kambiz » January 20th, 2011, 11:39 am

Thanks for sharing the information!

It is amazing how Microsoft can make a simple thing so complicated.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: Page by E-mail from IE

Postby Stefan » January 21st, 2011, 1:05 pm

One last thing, to complete the process you need to add a string key to HKLM\SOFTWARE\Clients\Mail\YourApp\ called DLLPath which contains the path to your DLL.
User avatar
Stefan
Moderator
Moderator
 
Posts: 128
Joined: September 27th, 2004, 9:40 am
Location: Tilburg, The Netherlands


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron