Open Outlook by clicking an email in the TDBGrid component in Delphi

1

I'm making a utility where you'll get the employee's name, your extension, and your email. I would like that when clicking on the email already open Outlook. How could this be possible?

    
asked by anonymous 11.02.2014 / 14:15

2 answers

1

Add the unit shellapi and try this in the CellClick event. Change the 'EMAIL FILE' by the name of your field, upper case 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;
    
11.02.2014 / 14:29
0

Some time ago I had a similar need and I was able to resolve with Sertac Akyuz's answer in SOEN using the Method MailItem.Display .

Basically you need to declare the 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 that seems more appropriate, such as OnCellClick .

Note that for the method to work, it is necessary for the machine to have Outlook installed. I have not tested it in Windows 8 but I believe it only works with Outlook for Desktop.

    
11.02.2014 / 15:36