Ver Mensaje Individual
  #2  
Antiguo 04-06-2010
Avatar de erickahr
erickahr erickahr is offline
Miembro
 
Registrado: feb 2010
Posts: 94
Reputación: 15
erickahr Va por buen camino
Lightbulb Saludos

mira yo batalle un poco con ese asunto de los Mails, principalmente mi problema era para los correos de GMail por el asunto de SSL, aki te dejo ati y a quien le pueda servir este fuente, es una DLL que hice a basandome en un codigo de Roman. Espero sea de utilidad, al menos como guia o pauta, para sacar su propio codigo.

Código Delphi [-]
library SendgMail;
{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }
uses
  ShareMem,
  SysUtils, IdAttachment, IdAttachmentFile, IdMessage, IdIOHandler,
  IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL, IdBaseComponent,
  IdComponent, IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase,
  IdMessageClient, IdSMTPBase, IdSMTP, Classes;

var
  SMTP:         TIdSMTP;
  ManejadorSSL: TIdSSLIOHandlerSocketOpenSSL;
  Mensaje:      TIdMessage;
{$R *.res}
 
Procedure InitSMTP(smtpHost,smtpContra,smtpPuerto,smtpUser: String); stdCall;
begin
SMTP        := TidSMTP.Create;
ManejadorSSL:= TIdSSLIOHandlerSocketOpenSSL.Create;
Mensaje     := TIdMessage.Create;
  with SMTP do
    begin
    AuthType:=atDefault;
    Host:=smtpHost;
    IOHandler:=ManejadorSSL;
    MailAgent:='Email 6.1';
    Password:=smtpContra;
    PipeLine:=False;
    Port:=StrToInt(smtpPuerto);
    UseEhlo:=True;
    UserName:=smtpUser;
    UseTLS:=utUseExplicitTLS;
    end;
  with  ManejadorSSL do
    begin
    RecvBufferSize:=65000;
    SendBufferSize:=65000;
    SSLOptions.Method:=sslvSSLv3;
    SSLOptions.Mode:=sslmUnassigned;
    SSLOptions.VerifyDepth:=0;
    SSLOptions.VerifyMode:=[];
    UseNagle:=False;
    end;
end;

procedure MandaAdjunto(sArchivo, FAddress, TAddress, xMensaje, xAsunto: String); stdCall;
begin
  With Mensaje do
    begin
    From.Address              := FAddress;
    Recipients.EMailAddresses := TAddress;
    Subject                   := xAsunto
    Body.Text                 := xMensaje;
    TIdAttachmentFile.Create(MessageParts, sArchivo);
    end;
  With SMTP do
    begin
    try
      Connect;
    except
      raise Exception.Create( 'Error al conectar con el servidor.' );
    end;
    if Connected then
      begin
      try
        Send(Mensaje);
        Enviado := True;
      except
        raise Exception.Create( 'Error al enviar el mensaje.' );
      end;
    end;
      try
        Disconnect;
      except
        raise Exception.Create( 'Error al desconectar del servidor.' );
      end;
    end;
    End
end;
exports InitSMTP;
exports MandaAdjunto;

begin
end.


Esto te genera una dll llamada SendGMail.dll.
Una vez publecada la DLL la pones en el directorio de tu aplicacion, y puedes llamar los procedimientos de la siguiente forma, por ejemplo:

Primero llamamos a los procedimientos desde el exterior:
Código Delphi [-]
procedure InitSMTP(smtpHost,smtpContra,smtpPuerto,smtpUser: String); stdcall external 'SendgMail.dll';
procedure MandaAdjunto(sArchivo, FAddress, TAddress: String; Fecha: TDateTime); stdcall external 'SendgMail.dll';

Despues en un boton podemos poner lo siguiente para ejecutar el envio del mail.

Código Delphi [-]
 InitSMTP(smtp.gmail.com,******,587,erickahr86); 
 MandaAdjunto('C:\Archivo.rar',remitente@gmail.com , destinatario@gmail.com, Memo1.text, Edit1.text); stdCall;


Espero les sea de ayuda compañeros, y trato de devolver a la cumunidad una minimaparte de todo lo que me ha dado.
__________________
Nadie puede separar su fe de sus actos, o sus creencias de sus afanes
Responder Con Cita