Open Outlook by clicking an email on the Tdbgrid component in Delphi

Asked

Viewed 1,492 times

1

I am making a utility where will have the employee name, your extension and your email.
I would like when clicking on the email to already open Outlook. As this would be possible?

2 answers

1


Add the Unit shellapi and try this in the Cellclick event. Change the 'EMAIL FIELD' to your field name, uppercase if applicable.

    procedure TForm1.DBGrid1CellClick(Column: TColumn);
    begin

      if (Column.Field.Name = 'CAMPO EMAIL') then
      begin

        ShellExecute(handle, 'open', pchar('mailto:' + Column.Field.Value), nil, nil, sw_ShowNormal);

      end;


    end;
  • How do I add the Unit shellapi? Sorry I’m a beginner.

  • I found Unit shellapi’s code. I added it, but this with an error yet.

  • [dcc32 Error] mainRamais.pas(70): E2089 Invalid Typecast

  • [dcc32 Fatal Error] Utilities.kva.dpr(5): F2063 Could not Compile used Unit 'mainRamais.pas'

  • Are you putting the Shellapi into your uses or trying to copy its code into your application? Just add in uses...

  • I added it to my uses, and created a Unit with the code I found on a website

  • So, to execute what I gave you, just add the Shellapi no uses, and nothing else... There was some special reason for you to use another code?

  • found the bug, it worked. I used Winapi.Shellapi on uses, and changed pchar to Pwidechar

  • can tell me how to change mouse icon only in email ?

  • Opa legal, good to have helped... About the mouse, by the rules the right would be you post another question, all right? hugs

Show 5 more comments

0

Some time ago I had a similar need and managed to resolve with based on this response of Sertac Akyuz in the SOEN using the Mailitem.Display.

Basically you need to declare Unit ComObj and create a function like this:

procedure TFrmExemplo.EnviarEmail(Destinatario, Assunto, Mensagem: string;
  Anexo: TFileName);
var
  Outlook: OleVariant;
  Mail: Variant;
const
  olMailItem = $00000000;
begin
  try
    Outlook := GetActiveOleObject('Outlook.Application');
  except
    Outlook := CreateOleObject('Outlook.Application');
  end;
  Mail := Outlook.CreateItem(olMailItem);
  Mail.to := Destinatario;
  Mail.Subject := Assunto;
  Mail.Body := Mensagem;
  if Anexo <> EmptyStr then
    Mail.Attachments.Add(Anexo);
  Mail.Display;
end;

Once created just call the Event Handler which it considers most appropriate, such as OnCellClick.

It is worth noting that for the method to work it is necessary that the machine has Outlook installed. I have not yet tested on Windows 8 but I believe it works only with Outlook for Desktop.

  • Oops, cool... I was trying to remember this tip there to help the friend, but at the time I remembered the whole code... This way is better because you can compose the whole message ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.