Ver Mensaje Individual
  #2  
Antiguo 28-01-2025
Avatar de pgranados
pgranados pgranados is offline
Miembro
 
Registrado: sep 2022
Ubicación: México
Posts: 318
Reputación: 3
pgranados Va por buen camino
Ya intentaste con los componentes Indy? Usa el TIdSMTP, seria algo así:

Código Delphi [-]
procedure EnviarMensaje(Texto, RutaFile:String);
var
   SMTP: TIdSMTP;
   Mensaje: TIdMessage;
   Adjunto: TIdAttachment;
begin
    SMTP := TIdSMTP.Create(nil);
    SMTP.Username := 'tucorreo@mail.com';
    SMTP.Password := 'password';
    SMTP.Host := 'host';
    SMTP.Port := puertoaqui;

    if NecesitaAuth then
      SMTP.AuthType := satDefault
    else
      SMTP.AuthType := satNone;

    if NecesitaSSL then
    begin
      SMTP.IOHandler:= IdSSLIOHandlerSocketOpenSSL1;
      SMTP.UseTLS:= utUseExplicitTLS;
    end;

    // Creamos el contenido del mensaje
    Mensaje := TIdMessage.Create( nil );
    Mensaje.Clear;
    Mensaje.From.Address := 'tucorreo@mail.com';
    Mensaje.Subject := 'Asunto';
    Mensaje.Body.Text := Texto;
    Mensaje.Recipients.EmailAddresses := 'correodestino@correo.com';

    if FileExists( sAdjunto ) then
       Adjunto := TIdAttachmentFile.Create(Mensaje.MessageParts, RutaFile )
   else
       Adjunto:= nil;

    try
      SMTP.Connect;
    except
      raise SysUtils.Exception.Create(lsMsj);
    end;

    // Si ha conectado enviamos el mensaje y desconectamos
    if SMTP.Connected then
    begin
      // Enviamos el mensaje
      try
        SMTP.Send(Mensaje);
      except
        raise SysUtils.Exception.Create(lsMsj);
      end;

      // Hacemos la desconexión
      try
        SMTP.Disconnect;
      except
        raise SysUtils.Exception.Create( 'Error al desconectar del servidor.' );
      end;
    end;

    FreeAndNil( Adjunto );
    FreeAndNil( Mensaje );
    FreeAndNil( SMTP );

end;
Responder Con Cita