Ver Mensaje Individual
  #18  
Antiguo 16-02-2018
LuisHatake LuisHatake is offline
Miembro
NULL
 
Registrado: oct 2017
Posts: 14
Reputación: 0
LuisHatake Va por buen camino
Enviar archivo de excel por email

Hola gracias por responder. Mi problema es que no puedo enviar un archivo de excel adjunto.
El siguiente codigo lo utilizo y envio el correo electrónico a la perfección siempre y cuando quite esta linea: TIdAttachment.Create (DATA.MessageParts, '1.JPG');
no se como seria para adjuntar un archivo de excel. espero me puedan orientar, utilizo delphi xe7 y gracias!

Código Delphi [-]
procedure Gmail(username, password, totarget, subject, body: string);
var
  DATA: TIdMessage;
  SMTP: TIdSMTP;
  SSL: TIdSSLIOHandlerSocketOpenSSL;
begin
  SMTP := TIdSMTP.Create(nil);
  DATA := TIdMessage.Create(nil);
  SSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil);

  SSL.SSLOptions.Method := sslvTLSv1;
  SSL.SSLOptions.Mode := sslmUnassigned;
  SSL.SSLOptions.VerifyMode := [];
  SSL.SSLOptions.VerifyDepth := 0;

  DATA.From.Address := username;
  DATA.Recipients.EMailAddresses := totarget;
  DATA.subject := subject;
  DATA.body.text := body;
  DATA.ContentType := 'text / plain';
  //TIdAttachment.Create(DATA.MessageParts, ruta);
  TIdAttachment.Create (DATA.MessageParts, '1.JPG');


  SMTP.IOHandler := SSL;
  SMTP.Host := 'smtp.gmail.com';
  SMTP.Port := 587;
  SMTP.username := username;
  SMTP.password := password;
  SMTP.UseTLS := utUseExplicitTLS;

  SMTP.Connect;
  SMTP.Send(DATA);
  SMTP.Disconnect;

  SMTP.Free;
  DATA.Free;
  SSL.Free;
end;

El error que obtengo es el siguiente.
[dcc32 Warning] Unit2.pas(66): W1020 Constructing instance of 'TIdAttachment' containing abstract method 'TIdAttachment.OpenLoadStream'
Gracias de nuevo
Responder Con Cita