Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Internet (https://www.clubdelphi.com/foros/forumdisplay.php?f=3)
-   -   Enviar Correo (https://www.clubdelphi.com/foros/showthread.php?t=6057)

manuelpr 16-12-2003 21:39:29

Enviar Correo
 
Necesito con suma urgencia enviar correo con attach y que se abra mi cliente de correo antes de enviarlo, estube revisando en la seccion trucos y encontre "enviar correos en forma elegante", el cual no permite enviar con attach.

por favor si alguien a logrado modificar este truco, me puede indicar como.

gracias:confused:

Descendents 17-12-2003 00:56:45

añade esta linea

if (filen > '') then header := header + '&attachment="' + filen+'"';

filen es un string más, que lo declaras junto a mailto,mailsubject etc...

y donde haces MailTo := 'foro@clubdelphi.com';, etc... haces
filen := 'c:\s.txt';

a ver que tal

PD:Copiate la lines,haz un copy paste de la linea, porque parecen comillas simples, y hay algunas comillas dobles

saludos

manuelpr 17-12-2003 11:50:44

Gracias, pero no funciona

Descendents 17-12-2003 13:02:24

A mi me funciona.

ahora te pondre el código entero
A ver que tal

Descendents 17-12-2003 13:12:50

Yo uso delphi 7 y winxp, outlook 2000.

Si copias todo el código que te puesto y lo añades a un unit nuevo, pones un boton y un memo y lo pruebas, a mi me funciona

Código:


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,shellapi;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
  procedure RunDefaultMailer; 
    { Public declarations }
  end;


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


var
  Form1: TForm1;
  filen,
  MailTo,
  MailSubject,
  MailCC,        //  Carbon Copy
  MailBCC,        //  Blind Carbon Copy
  MailBody: String;


implementation

{$R *.dfm}


procedure TForm1.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;
  if (filen > '') then header := header + '&attachment="' + filen+'"';
  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
  filen := 'c:\r.txt';
  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;


end.


Saludos

manuelpr 17-12-2003 14:41:31

Yo lo tengo exactamente igual pero no funciona.

Trabajo con delphi 6 y Outlook Express

Saludos

Descendents 17-12-2003 19:01:06

ok el problema es outlook express.

Prueba esto

Código:

procedure TForm1.Button1Click(Sender: TObject);
const
  olMailItem = 0;
var
  Outlook, MailItem: OLEVariant;
begin
  try
    Outlook := GetActiveOleObject('Outlook.Application');
  except
    Outlook := CreateOleObject('Outlook.Application');
  end;

  MailItem := Outlook.CreateItem(olMailItem);
  MailItem.Recipients.Add('delphi at elists.org');
  MailItem.Subject := 'your subject';
  MailItem.Body := 'Visit: http://www.elists.org/mailman/listinfo/delphi';
  MailItem.Attachments.Add('C:\autoexec.bat');
  MailItem.Send;

  Outlook := Unassigned;
end;


Uses
Comobj


Suerte, a vder si sirve de algo.
Saludos

Descendents 17-12-2003 19:34:43

como ultimo si no te funciona prueba esto

Código:

procedure TForm1.Button1Click(Sender: TObject);
var
  pCh: PChar;
begin
  pCh :='mailto:pepito@yahoo.es?subject=sujeto&body=cuerpo&file="c:\index.htm"';
  ShellExecute(0, 'open', pCh, nil, nil, SW_SHOWNORMAL);
end;

Sino no tengo ni idea.

Si esto no te sirve, y lo consigues, comunicalo al foro como.

Yo no puedo probarlo, porque no tengo el express.

Pero con outlook esto me funciona.

Saludos


La franja horaria es GMT +2. Ahora son las 14:22:05.

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