title: Sending email via Google SMTP
body: <p>I am using this code to send emails via GMail (encrypted SMTP).</p>
  
  <pre><code>pocedure TForm5.SendEmail(const Recipients: string; const Subject: string; const Body: string);
  var
    Email: TIdMessage;
    SSLHandler: TIdSSLIOHandlerSocketOpenSSL;
  begin
    Email := TIdMessage.Create(nil);
    SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
  
    try
      SSLHandler.MaxLineAction := maException;
      SSLHandler.SSLOptions.Method := sslvSSLv23;
      SSLHandler.SSLOptions.Mode := sslmUnassigned;
      SSLHandler.SSLOptions.VerifyMode := [];
      SSLHandler.SSLOptions.VerifyDepth := 0;
  
      SMTP.IOHandler := SSLHandler;
      SMTP.Host := 'smtp.gmail.com';
      SMTP.Port := 587;
      SMTP.Username := 'test1@gmail.com';
      SMTP.Password := '**********';
      SMTP.UseTLS := utUseExplicitTLS;
  
      Email.From.Address := 'test1@gmail.com';
      Email.Recipients.EmailAddresses := Recipients;
      Email.Subject := Subject;
      Email.Body.Text := Body;
  
      SMTP.Connect;
      if SMTP.Connected then
       begin
        SMTP.Send(Email);
        SMTP.Disconnect;
       end;
  
    finally
      Email.Free;
      SSLHandler.Free;
    end;
  end;
  </code></pre>
  
  <p>The code is working from outside of Delphi IDE, but if ran from inside of the IDE it gives me an AV:</p>
  
  <blockquote>
    <p>{Project Tester.exe raised exception class $C0000005 with message
    'access violation at 0x7672bce7: read of address 0x675919d1'}</p>
  </blockquote>
  
  <p>I have also tried to change SSLHandler.SSLOptions.Method, but with the same result.</p>
  
  <p><strong>The Call Stack</strong></p>
  
  <p>I don't know how I forgot to mention the strage thing about the AV: The AV in not in the code above. If I press 'Break' it shows the ASM window. The program stops in kernel32.IsBadReadPtr.</p>
  
  <pre><code>kernel32.IsBadReadPtr:
  769CBCAB 6A0C             push $0c
  769CBCAD 6818BD9C76       push $769cbd18
  769CBCB2 E8410F0100       call $769dcbf8
  769CBCB7 A19460A576       mov eax,[$76a56094]
  769CBCBC 8BB02C010000     mov esi,[eax+$0000012c]
  769CBCC2 8B450C           mov eax,[ebp+$0c]
  769CBCC5 85C0             test eax,eax
  769CBCC7 743F             jz $769cbd08
  769CBCC9 8B4D08           mov ecx,[ebp+$08]
  769CBCCC 85C9             test ecx,ecx
  769CBCCE 0F8437BC0200     jz $769f790b
  769CBCD4 8D4401FF         lea eax,[ecx+eax-$01]
  769CBCD8 89450C           mov [ebp+$0c],eax
  769CBCDB 3BC1             cmp eax,ecx
  769CBCDD 0F8228BC0200     jb $769f790b
  769CBCE3 8365FC00         and dword ptr [ebp-$04],$00
  769CBCE7 8A01             mov al,[ecx]         &lt;------------ HERE
  769CBCE9 8D56FF           lea edx,[esi-$01]
  769CBCEC F7D2             not edx
  769CBCEE 8BC2             mov eax,edx
  769CBCF0 23C1             and eax,ecx
  769CBCF2 8945E4           mov [ebp-$1c],eax
  769CBCF5 21550C           and [ebp+$0c],edx
  769CBCF8 3B450C           cmp eax,[ebp+$0c]
  769CBCFB 0F85FBBB0200     jnz $769f78fc
  ...
  </code></pre>
  
  <p>The Call Stack is:</p>
  
  <ul>
  <li>Libeay.DLL,  </li>
  <li>Cpruptsp.dll,  </li>
  <li>LoadLibraryEXA,  </li>
  <li>OnlineArmor.DLL, </li>
  <li>IsBadReadPtr.DLL</li>
  </ul>
  
  <p>OnlineArmor is my firewall!!!!! I don't want to blame it so quickly... but is it possible it is the root if this AV?    </p>
  
  <p>I am using:<br>
    this SSL DLL: <a href="http://indy.fulgan.com/SSL/openssl-0.9.8r-i386-win32-rev2.zip" rel="nofollow noreferrer">http://indy.fulgan.com/SSL/openssl-0.9.8r-i386-win32-rev2.zip</a><br>
    Delphi XE<br>
    Indy 10  </p>