Sending email using Gmail

8

I need help with emailing GMail using Indy10 and Delphi 7 . I think the Delphi version should not matter so much, but the Indy version right?

I just downloaded Indy10 for indy.fulgan.com/ZIP/ and I've already installed the components.

The Dll's I got from the indy_openssl096.zip package that has SSL.zip in that directory. And I'm getting the following error:

  

raised exception class EIdOSSLCouldNotLoadSSLLibrary with message 'Could not load SSL library.'

Now when you download the openssl-1.0.0l-i386-win32 version, indy.fulgan. with / SSL / I get the following error:

  

'RCPT first. d8sm5855899vek.11 - gsmtp '.

I'm following the following example of Marco Cantu marcocantu.com/tips/oct06_gmail .

That is:

Components DFM:

object IdMsg: TIdSMTP
    OnStatus = IdSMTP1Status
    IOHandler = IdSSLSocket
    Host = 'smtp.gmail.com'
    Port = 587
    SASLMechanisms = <>
    UseTLS = utUseExplicitTLS
    Username = '****@gmail.com'
    Password = '****'
end
object IdSSLSocket: TIdSSLIOHandlerSocketOpenSSL
    Destination = 'smtp.gmail.com:587'
    Host = 'smtp.gmail.com'
    MaxLineAction = maException
    Port = 587
    SSLOptions.Method = sslvTLSv1
    SSLOptions.Mode = sslmUnassigned
    SSLOptions.VerifyMode = []
    SSLOptions.VerifyDepth = 0
    OnStatusInfo = IdSSLSocketStatusInfo
end

Upload method:

procedure TMainForm.enviarButtonClick(Sender: TObject);
begin
  IdMsg.Clear;
  IdMsg.ClearBody;
  IdMsg.ClearHeader;

  IdMsg.From.Address := '****@gmail.com';
  IdMsg.From.Name := 'NOME';

  IdMsg.Body.Text := 'Data/Hora: ' + DateTimeToStr(Now);
  IdMsg.Body.Add('Teste');

  IdSmtp.Connect();
  IdSmtp.Send(IdMsg);
  IdSmtp.Disconnect;
end;

So, what am I doing wrong after all?

    
asked by anonymous 21.03.2014 / 17:45

1 answer

8
  

Response derived from: Delphi 7 and gmail (connection with authentication)

Gmail uses the encryption system , and to connect our application to it, we need two specific dll's that would be:

libeay32.dll and ssleay32.dll . ( download them can be found here )

Once you have the dll's in hand, unzip them in the C:\WINDOWS\System32 directory.

Enter the following components: IdSMTP (Indy Clients palette), IdMessage (Indy Misc palette), IdSSLIOHandlerSocket (Indy I / O Handles palette), and Button .

To facilitate, rename the components for SMTP , MSG and SSLSocket respectively.

Now on OnCreate of form:

procedure TForm1.FormCreate(Sender: TObject);
Begin
   with SMTP do
   begin
      AuthenticationType := atLogin;
      Host := 'smtp.gmail.com';
      IOHandler := SSLSocket;
      Password := 'sua senha no gmail';
      Port := 465;
      Username := '[email protected]'; //não esqueça o @gmail.com!!
  end;
  SSLSocket.SSLOptions.Method := sslvSSLv2;
  SSLSocket.SSLOptions.Mode := sslmClient;
end;

Simple example of one-button use:

procedure TForm1.Button1Click(Sender: TObject);
begin
  with MSG do
  begin
    Body.Add('corpo da mensagem');
    From.Address := 'email do remetente'; //opcional
    From.Name := 'nome do remetente'; //opcional
    Recipients.Add;
    Recipients.Items[0].Address := '[email protected]';
    Recipients.Items[0].Name := 'nome do destinatario'; //opcional
    Subject := 'assunto da mensagem';
  end;
  try
    SMTP.Connect();
    SMTP.Send(MSG);
    SMTP.Disconnect;
  except
    ShowMessage('Falha no envio!');
    exit;
  end;
  ShowMessage('Mensagem enviada com sucesso!');
end;
    
21.03.2014 / 19:37