Send Email with Indy and SSL [Edit]

I must send a mail with Indy 10.0.1.1 and SSL
This is my code:

procedure SendEmail;
var
  IdMessage: TIdMessage;
  SMTP: TIdSMTP;
  SSLHandler: TIdSSLIOHandlerSocketOpenSSL;
  IdUserPassProvider: TIdUserPassProvider;
  IdSASLCRAMMD5: TIdSASLCRAMMD5;
  IdSASLCRAMSHA1: TIdSASLCRAMSHA1;
  IdSASLPlain: TIdSASLPlain;
  IdSASLLogin: TIdSASLLogin;
  IdSASLSKey: TIdSASLSKey;
  IdSASLOTP: TIdSASLOTP;
  IdSASLAnonymous: TIdSASLAnonymous;
  IdSASLExternal: TIdSASLExternal;
begin
  IdMessage := TIdMessage.Create(nil);
  try
    IdMessage.ContentType := 'text/plain';
    IdMessage.Charset := 'UTF-8';
    IdMessage.Body.Text:='Prova di invio tramite SSL';
    IdMessage.Sender.Text := 'giovanellip@gmail.com';
    IdMessage.From.Name := 'Paolo Giovanelli';
    IdMessage.From.Address := 'giovanellip@gmail.com';
    IdMessage.ReplyTo.EMailAddresses := 'giovanellip@gmail.com';
    IdMessage.Recipients.EMailAddresses := 'giovanellip@gmail.com';
    IdMessage.Subject := 'Prova invio SSL';
    IdMessage.Priority := TIdMessagePriority.mpHighest;
    IdMessage.CCList.EMailAddresses := '';
    IdMessage.ReceiptRecipient.Text := '';
    IdMessage.BccList.EMailAddresses := '';

    SMTP := TIdSMTP.Create(nil);
    try
        SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(SMTP);
        SSLHandler.MaxLineAction := maException;
        SSLHandler.SSLOptions.Method := sslvSSLv23;
        SSLHandler.SSLOptions.Mode := sslmClient;
        SSLHandler.SSLOptions.VerifyMode := [];
        SSLHandler.SSLOptions.VerifyDepth := 0;
        SMTP.IOHandler := SSLHandler;
        SMTP.UseTLS := utUseExplicitTLS;

        SMTP.AuthType := satSASL;

        IdUserPassProvider := TIdUserPassProvider.Create(SMTP);
        IdUserPassProvider.Username := 'giovanellip@gmail.com';
        IdUserPassProvider.Password:= myPassword;   // my mail password

        IdSASLCRAMSHA1 := TIdSASLCRAMSHA1.Create(SMTP);
        IdSASLCRAMSHA1.UserPassProvider := IdUserPassProvider;
        IdSASLCRAMMD5 := TIdSASLCRAMMD5.Create(SMTP);
        IdSASLCRAMMD5.UserPassProvider := IdUserPassProvider;
        IdSASLSKey := TIdSASLSKey.Create(SMTP);
        IdSASLSKey.UserPassProvider := IdUserPassProvider;
        IdSASLOTP := TIdSASLOTP.Create(SMTP);
        IdSASLOTP.UserPassProvider := IdUserPassProvider;
        IdSASLAnonymous := TIdSASLAnonymous.Create(SMTP);
        IdSASLExternal := TIdSASLExternal.Create(SMTP);
        IdSASLLogin := TIdSASLLogin.Create(SMTP);
        IdSASLLogin.UserPassProvider := IdUserPassProvider;
        IdSASLPlain := TIdSASLPlain.Create(SMTP);
        IdSASLPlain.UserPassProvider := IdUserPassProvider;

        SMTP.SASLMechanisms.Add.SASL := IdSASLCRAMSHA1;
        SMTP.SASLMechanisms.Add.SASL := IdSASLCRAMMD5;
        SMTP.SASLMechanisms.Add.SASL := IdSASLSKey;
        SMTP.SASLMechanisms.Add.SASL := IdSASLOTP;
        SMTP.SASLMechanisms.Add.SASL := IdSASLAnonymous;
        SMTP.SASLMechanisms.Add.SASL := IdSASLExternal;
        SMTP.SASLMechanisms.Add.SASL := IdSASLLogin;
        SMTP.SASLMechanisms.Add.SASL := IdSASLPlain;

        SMTP.Host := 'smtp.gmail.com';
        SMTP.Port := 587;
        SMTP.ConnectTimeout := 30000;
        SMTP.UseEHLO := True;
        SMTP.Connect;
        try
          SMTP.Send(IdMessage);
        finally
          SMTP.Disconnect;
        end;
    finally
      SMTP.Free;
    end;
  finally
    IdMessage.Free;
  end;
end;

I connect to gmail server but when I send my email I have this excetpion: "Connection closed gracefully" and the email is not sent
Can someone help me?
0
Paolo
12/9/2013 3:06:12 PM
embarcadero.delphi.non-tech 5933 articles. 1 followers. Follow

6 Replies
5063 Views

Similar Articles

[PageSpeed] 43

>      IdMessage.BccList.EMailAddresses := '';
>
>      SMTP := TIdSMTP.Create(nil);
>      try
>          SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(SMTP);
>          SSLHandler.MaxLineAction := maException;
>          SSLHandler.SSLOptions.Method := sslvSSLv23;
>          SSLHandler.SSLOptions.Mode := sslmClient;
>          SSLHandler.SSLOptions.VerifyMode := [];
>          SSLHandler.SSLOptions.VerifyDepth := 0;
>          SMTP.IOHandler := SSLHandler;
>          SMTP.UseTLS := utUseExplicitTLS;


I use these options and it works well:
            sslIOHandler := TIdSSLIOHandlerSocketOpenSSL.Create;
            SMTP.IOHandler := sslIOHandler;
            SMTP.UseTLS := utUseRequireTLS;

kind regards
    Mike
0
Michael
12/9/2013 3:48:33 PM
I try this change to my code:

// old code version

//        SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(SMTP);
//        SSLHandler.MaxLineAction := maException;
//        SSLHandler.SSLOptions.Method := sslvSSLv23;
//        SSLHandler.SSLOptions.Mode := sslmClient;
//        SSLHandler.SSLOptions.VerifyMode := [];
//        SSLHandler.SSLOptions.VerifyDepth := 0;
//        SMTP.IOHandler := SSLHandler;
//        SMTP.UseTLS := utUseExplicitTLS;

// new code version        
        SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create;
        SMTP.IOHandler := SSLHandler;
        SMTP.UseTLS := utUseRequireTLS;

but it doesn' t run again: always the same exception.
the change is wrong?
0
Paolo
12/9/2013 3:58:33 PM
Paolo wrote:

> SSLHandler.SSLOptions.Method := sslvSSLv23;

Use either sslvSSLv3 or sslvTLSv1 instead.

--
Remy Lebeau (TeamB)
0
Remy
12/9/2013 8:12:48 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> Paolo wrote:
> 
> > SSLHandler.SSLOptions.Method := sslvSSLv23;
> 
> Use either sslvSSLv3 or sslvTLSv1 instead.
> 
> --
> Remy Lebeau (TeamB)

I try with both but I have always the same result
Any idea?
Greetings Paolo
0
Paolo
12/10/2013 8:19:17 AM
>
> I try with both but I have always the same result
> Any idea?

Any chance that you first try that with a normal mail client like
Thunderbird?

kind regards
   Mike
0
Michael
12/10/2013 8:47:07 AM
Paolo wrote:

> I must send a mail with Indy 10.0.1.1 and SSL
> This is my code:

Using the latest Indy 10 SVN snapshot, the exact code you showed works as-is 
for me using my GMail account.  The only thing I had to change was the GMail 
username/password and the sender/recipient addresses, nothing else was changed. 
 The email was sent correctly as expected.

Do you have 2-factor authentication enabled on your GMail account?  If so, 
make sure you are using a 2-factor application password and not your main 
GMail password.

--
Remy Lebeau (TeamB)
0
Remy
12/10/2013 6:39:50 PM
Reply:

Similar Artilces:

using Indy to send a email with SSL
Hello - I have been using a very simple procedure shown here written with Delphi 2010 to send emails to selected recipients using the Indy components which shipped with my D2010. I am using hMailServer and the procedure works very well as written. I have now decided to install a SSL certificate in hMail for encryption purposes and have gone through the certificate installation process and I have attached it to my mail ports. When I run the procedure now the application locks up. I can turn the problem on and off just by attaching or detaching the SSL certificate on my SMTP port in hMa...

I can`t send email using Indy [Edit]
I have such a exception: +First chance exception at $7C812AFB. Exception class EIdSMTPReplyError with message 'RCPT first (#5.5.1)+ +'. Process Project1.exe (956)+ I use Indy 10 rev. 3670. C++ Builder 2009. This exception appear on old project, but if I build a new project using Indy there is no problem. I tried to delete all components Indy and add them again to project but nothing changed. How can I change old project to work properly ? IdMessage1->Clear(); IdMessage1->From->Name = "j.ai@ago.pl"; IdMessage1->From->Address = "j.a@ago.pl"; I...

Delphi XE and Indy SSL connection with trusted certificate [Edit]
Hi, In the procedure *TIdSSLContext.InitContext(CtxMode: TIdSSLCtxMode)*; (IdSSLOpenSSL.pas) Lines {code} // CA list if RootCertFile <> '' then begin {Do not Localize} SSL_CTX_set_client_CA_list(fContext, IndySSL_load_client_CA_file(RootCertFile)); end{code} In the function *IndySSL_load_client_CA_file(const AFileName: String): PSTACK_OF_X509_NAME;* The second time through the loop {code}while (PEM_read_bio_X509(LB, @LX, nil, nil) <> nil) do begin{code} raise an exception (EAccessViolation in libeay32.dll) when my RootCertFile have more than ...

Problems sending emails with attachments in Indy SMTP in Delphi 2009
Hi, I'm working with Delphi 2009 fully updated (12.0.3420.21218 with Update Pack 3), and I had the original version of the Indy 10.2.5. All attachments were going with a file name ATT000043.dat, instead of the correct name. I updated to the latest Indy from the Dev Snapshot, and it went to version 10.5.7. However, now the attachment does not appear as an attachment at all, the the message appears as: This is a multi-part message in MIME format --HF2WOHttwwLp1TZg=_wwY6H2qbRC0RDTyU Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Content-Disposition: inline H...

Converting Delphi 2007 Indy 10.2.3 to Delphi 2009 Indy 10.5.5 [Edit]
Hello, I am currently attempting to port over a Delphi 2007 project that uses Indy 10.2.3 (very successfully) to Delphi 2009 and Indy 10.5.5 (I just got the latest development build this morning). I think I am running into an encoding issue, but am not sure. Specifically, IDHTTP with SSL calls an old CGI and the CGI returns a .zip file and I then save it to the disk. In 2007 and before this worked perfectly. In 2009, it is not. Here is the examples of the 2 different results (though cut way short in the post) I am getting back: 2007: 'PK'#3#4#$14#0#0#0#8#0'rLQ9žrPb€'#0...

Delphi XE5 Android App dies preparing INDY email [Edit]
Can someone help me with the following code, it connects and authenticates the idsmtp connection but the app dies on the line:- idMessage1.Recipients.EMailAddresses:='colin@gmail.com'; Anyone had and overcome this problem? procedure TForm3.Button1Click(Sender: TObject); begin if idSMtp1.Connected = true then idsmtp1.Disconnect; idsmtp1.Connect; //THIS LINE WORKS idSmtp1.Authenticate; //THIS LINE WORKS idMessage1.Clear; //THIS LINE WORKS ...

Send Email with Indy smtp
-- Indy component smtp and MailMessage -- under win 32 works correct, no problems. -- under debug for IOS Device: The IOS APP hang complete! -- lines source code: MailMessage.Recipients.EMailAddresses := empfaenger ; idEmailAdress.pas: line 715 EMail.Text := TrimLeft(AList); !!!!! no error nothing app hang! here is my source code: try try MailMessage.From.Address := 'sender.adress@...' ; MailMessage.Subject := 'Hello again'; MailMessage.Body.Text := Memo...

Delphi XE2, Indy 10
Dear folks The following code is supposed to send a text string to a client that is listening on a set port and ip address. The connection works fine. The problem is that nothing seems to be sent. {code} function TFCSelectForm.SendNitroMessage(NitroRequest: String): String; var sStrm: TMemoryStream; begin try sStrm := TMemoryStream.Create; try sStrm.WriteBuffer(Pointer(NitroRequest)^,Length(NitroRequest)); // sStrm shows as () in the debugger IdTCPClient1.IOHandler.Write(sStrm, 0, False); sStrm.Position := 0; finally ...

"SSL is not available on this server" Exception Sending Emails with Indy
Hi I'm using the Indy (version 10.6.0.5122) TidSMTP component on Delphi XE6 to send emails (see component details below). object SMTP: TIdSMTP OnStatus = SMTPStatus IOHandler = IdSSLIOHandlerSocketOpenSSL1 Host = 'smtp.gmail.com' Password = '***' Port = 587 SASLMechanisms = <> UseTLS = utUseExplicitTLS Username = 'username' Left = 480 Top = 76 end object IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL Destination = 'smtp.gmail.com:587' Host = 'smtp.gmail.com' ...

Sending email to non-registered email addresses
Hello, I there a way to send email(add to a bug entry's cc list) to email adresses that are not registered in the bugzilla system Under Bugzilla Version 2.18rc3 Thanks -wdj On 4/22/05, Weddie Jackson <weddiedjackson@netscape.net> wrote: > I there a way to send email(add to a bug entry's cc list) to email > adresses that are not registered in the bugzilla system No. -- http://wurblzap.net/ Bugzilla hosting and professional support On 4/22/05, Weddie Jackson <weddiedjackson@netscape.net> wrote: > I there a way to send email(add to a b...

Non existing email address cancels sending to other email addresses
Hello ppl.. My WebApp sends emails to a series of email addresses without any problem... the problem is that when i send a email to a series of email addresses which contains a non existing email account... the email doesn't go at all.. Do you know what's the problem and what can be the resolution? Thanks in advance Bracoute How are you running the email process? Is it running in multiple threads so that more than 1 is sending at a time? If not, this should take care of that. Perhaps checking the email addresses for validation before allowing them to be entered into the databas...

Can't send emails to non-local email accounts
I'm really pissed at this now, I have been trying my best to research for the reason why this following method of mine doesn't send emails to non-local email accounts?? The method is as very well-known one as follows:  1 Sub SEM(ByVal from As String, ByVal recepient As String, ByVal subject As String, ByVal body As String, Optional ByVal bcc As String = "", Optional ByVal cc As String = "") 2 3 Try 4 ' Instantiate a new instance of MailMessage 5 Dim mMailMessage As New System.Net.Mail.MailMess...

sending email with indy
Hello! I have an app which sends emails with the TIdSMTP component. The app was working with OK so far, but from yesterday (in my customer PC - in mine it still works fine) I receive this error: Socket Error # 10060 Connection timed out. Googling I've found that you can make some changes in the windows registry to solve the problem. I didn't tried that yet, because I'd like to know what is causing the problem. I mean: something changed in that PC since yesterday (outside my app), but I can figure out what! thanks! Sergio sergio wrote: > Hello! I hav...

Mass Email sending or Bulk sending email
  i have a Problem regarding Email sending ie : Bulk sending mails --> let me explain Clearly i have an excel sheet in that there are around 3000 Records and in that each and ever record has a unique email id( it can be either gmail , yahoo. or hotmail )so , now i need a soluction for how to send a Bulk email at a timeas i told earlier  , each record contain Unique email id , so i need to send email for individual recodes in excel with appropriate record data  for the above probm , i have writen a program with foreach loop --> it is like, i have taken a co...

Web resources about - Send Email with Indy and SSL [Edit] - embarcadero.delphi.non-tech

Edits Quarterly
“Short narratives in film and photography”, by Ian Coyle. Do yourself a favor and view it on a big display in Safari in full-screen mode.

File:Edit-copy purple.svg - Wikipedia, the free encyclopedia
This file contains additional information, probably added from the digital camera or scanner used to create or digitize it.If the file has been ...

Articles with edits awaiting review - Wikipedia, the free encyclopedia
As part of a Request for Comment on pending-changes protection , a third phase considered its use in the short term. In accordance with consensus ...

Facebook Android App Update Includes Privacy Settings Icon, Structured Status Updates, Ability To Edit ...
... Inside Facebook reported that the update also extends the availability of structured status updates , as well as the ability for users to edit ...

Nick Gordon digitally edits late Bobbi Kristina Brown in controversial Christmas card
He may be facing a US$40 million lawsuit for her wrongful death, but that didn't stop Nick Gordon from sharing a controversial Christmas card ...

Kate Middleton to guest-edit the UK section of The Huffington Post
The Duchess of Cambridge will guest-edit the UK section of The Huffington Post to highlight child mental health issues, Kensington Palace says. ...

Livestream’s new Movi camera allows users to edit video while filming live
... iOS app. Thanks to the high-resolution 4K sensor, users can select from up to nine different virtual camera angles. Users can even edit video ...

A legal storm is brewing over a startup backed by Bill Gates that wants to edit people's genes by 2017 ...
A patent fight has been brewing over a new gene-editing technology that could be worth hundreds of millions, and it could throw a wrench in the ...

Duchess Kate will guest-edit HuffPo UK for one day, from Kensington Palace
... to center around children’s issues? Well, Kate is going to do more work on that issue. For one day. In February. She’s going to guest-edit The ...

Gallery: The Daily Edit 12.14.15
Charlotte Observer Gallery: The Daily Edit 12.14.15 Charlotte Observer Real Madrid's Karim Benzema, second right, and Cristiano Ronaldo, second ...

Resources last updated: 1/17/2016 5:41:09 PM