title: Troubleshooting EIdConnClosedGracefully Exceptions?
body: <p>The software we run using Delphi 7 generates and sends reports via email to various stakeholders. Of the roughly 30-40 reports transmitted daily, 2-4 different ones each day fail due to the exception: "EIdConnClosedGracefully"</p>
  
  <p>I'm trying to trace why this is happening and how to catch this in the code. Here's what we have so far:</p>
  
  <pre><code>try
     // Code that Populates "mess" (a tIdMessage variable)
  
     if (not nSMTP.Connected) then
     begin
       nSMTP.Connect;
     end;
  
     try
       nSMTP.Send(mess);      
     except on E : Exception do
       begin
         resend := E.Message;
         // AutoReports_ExceptionMessage is a string that holds the Exception message
         AutoReports_ExceptionMessage := 'Attempt #1: ' + resend; 
       end;
     end;
  
     if (resend &lt;&gt; '') then   // If there is an exception triggered, resend the email
     begin
       try
         nSMTP.Send(mess);
       except on E : Exception do
         begin
           resend := E.Message;
           AutoReports_ExceptionMessage := 'Attempt #2: ' + resend;  
         end;
       end;
     end
  
  finally
    mess.Free;
  end;
  </code></pre>
  
  <p>Also, when the EIdConnClosedGracefully is triggered, it always displays "Attempt #2: Connection Closed Gracefully." and never "Attempt #1: Connection Closed Gracefully"</p>
  
  <p>Any suggestions?</p>