Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Trucos (https://www.clubdelphi.com/foros/forumdisplay.php?f=52)
-   -   Enviar un email. Método elegante (https://www.clubdelphi.com/foros/showthread.php?t=80489)

marcoszorrilla 29-06-2006 22:22:15

Enviar un email. Método elegante
 
Código Delphi [-]
Un Form, Un TMemo y un TButton.
Codigo de Carlos Conca (ClubDelphi)

uses ShellApi;

Const
  EOL = '%0D%0A';           //   end of line
  Signature = EOL + EOL + 'Saludos desde París' + EOL + 'Carlos Conca';

Var
  MailTo,
  MailSubject,
  MailCC,         //  Carbon Copy
  MailBCC,        //  Blind Carbon Copy
  MailBody: String;


procedure RunDefaultMailer;
var
  header,
  mail : String;
  ShellResult : integer;
begin
  if (MailTo ='') then begin  //  también funciona sin destinatario
     ShowMessage('Falta el destinatario...');
     Exit;
  end;
  header := 'mailto:' + MailTo;
  if (MailSubject >'') then header := header + '?Subject=' + MailSubject;
  if (MailCC >'') then header := header + '&cc=' + MailCC;
  if (MailBCC >'') then header := header + '&bcc=' + MailBCC;
  mail := header + '&body=' + MailBody + Signature;
  ShellResult := ShellExecute(Application.mainform.Handle,'open',PChar(mail), nil, nil, SW_MAXIMIZE);
  //SHOWDEFAULT);
  if (ShellResult <= 32) then ShowMessage('Error Num '+IntToStr(ShellResult)+' en ShellExecute.'+
  #13+'Consulte la ayuda de Delphi.'+#13+'lenght(mail) =
'+IntToStr(length(mail)));
end;


procedure TForm1.Button1Click(Sender: TObject);
var
  n: Integer;
begin
  MailTo := 'foro@clubdelphi.com';
  MailSubject := 'Cómo enviar un mail';
  MailCC := 'gon@idecnet.com';
  MailBCC := 'Billy@Microsoft.com';
  MailBody := '';
  if (Memo1.Lines.Count > 1) then begin
     MailBody := MailBody + Memo1.Lines[0];
     for n := 1 to Memo1.Lines.Count - 1 do
     MailBody := MailBody + EOL + Memo1.Lines[n];
  end;
  RunDefaultMailer;
end;

Nomad 02-01-2008 16:52:44

No hay una forma de que lo envie automaticamente, si necesidad de que el usuario le de enviar?


La franja horaria es GMT +2. Ahora son las 18:24:35.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi