unit UfrmPrincipal;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,
IdIOHandler, IdIOHandlerSocket, IdSSLOpenSSL, IdMessage,
IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdMessageClient, IdSMTP;
type
TfrmPrincipal = class(TForm)
mCuerpoEmail: TMemo;
edAsuntoEmail: TEdit;
edServidorSmtp: TEdit;
lbAsuntoEmail: TLabel;
lbCuerpoEmail: TLabel;
lbServidorSmtp: TLabel;
edNombreUsuario: TEdit;
btnEnviarEmail: TButton;
lbNombreUsuario: TLabel;
edEmailRemitente: TEdit;
lbEmailRemitente: TLabel;
edContrasenaUsuario: TEdit;
edEmailDestinatario: TEdit;
lbEmailDestinatario: TLabel;
lbContrasenaUsuario: TLabel;
IdSMTP: TIdSMTP;
IdMessage: TIdMessage;
IdSSLIOHandlerSocket: TIdSSLIOHandlerSocket;
OpenDialog1: TOpenDialog;
Button1: TButton;
procedure btnEnviarEmailClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
end;
var
frmPrincipal: TfrmPrincipal;
Adjunto : String;
implementation
{$R *.dfm}
procedure TfrmPrincipal.btnEnviarEmailClick(Sender: TObject);
begin
with IdMessage do
begin
Body.Clear();
Recipients.Clear();
Sender.Address := edEmailRemitente.Text;
Recipients.EMailAddresses := edEmailDestinatario.Text;
Subject := edAsuntoEmail.Text;
Body.AddStrings(mCuerpoEmail.Lines);
if FileExists(Adjunto) then
with TIdAttachment.Create(MessageParts,Adjunto) do
begin
ContentType := 'binary';
end
end;
with IdSMTP do
begin
IOHandler := IdSSLIOHandlerSocket;
IdSSLIOHandlerSocket.SSLOptions.Method := sslvSSLv23; IdSSLIOHandlerSocket.SSLOptions.Mode := sslmUnassigned;
IdSSLIOHandlerSocket.SSLOptions.VerifyMode := [];
IdSSLIOHandlerSocket.SSLOptions.VerifyDepth := 0;
Port := 465;
Host := edServidorSmtp.Text;
AuthenticationType := atLogin;
Username := edNombreUsuario.Text;
Password := edContrasenaUsuario.Text;
try
Connect(5000);
except
raise Exception.Create('Error de Conexión');
end;
btnEnviarEmail.Enabled := false;
try
Send(IdMessage);
ShowMessage('Correo enviado con éxito');
finally
btnEnviarEmail.Enabled := true;
end;
if Connected then
Disconnect();
end;
end;
procedure TfrmPrincipal.Button1Click(Sender: TObject);
begin
if openDialog1.Execute then
adjunto := openDialog1.Filename;
end;
end.