title: Bounce email handling mailbox full using salesforce triggers
body: <p>I'm trying to solve the bouncing email issue based on "Mail box full" by creating a trigger that resends the message if the message contains "mail box full".</p>
  
  <p>The issue I'm facing is that I need to limit the number of resend to 3 times.
  What I have now keeps resending the email as soon as a bounced email is received.  </p>
  
  <p>My trigger is </p>
  
  <pre><code>trigger trgBouncedEmails on EmailMessage (after insert) {
  
    for(EmailMessage myEmail: trigger.New) {
  
  
      //mail box full bounced email 
      if (myEmail.HtmlBody.contains('full'))
      {
  
          Case[] parentCase = [Select c.Id from Case c where c.Id =: myEmail.ParentId];
  
  
           if (myEmail.Subject.contains('Financial Review'))
                  parentCase[0].Resend_Email_Send__c = true;  // this will trigger a workflow to send the email again.
  
            Update parentCase;
                }
        }
  }
  </code></pre>
  
  <p>How can I limit the resending, is there a way I can set a wait time before I do the "Update parentCase"</p>
  
  <p>Is there a better way to solve this issue, knowing that I have different types of emails, each one has a different template and a different purpose.</p>
  
  <p><strong>EDIT</strong>
  The system should automatically re-send the email 3 times in the frequency of 24hours, and then stops resending after 24hrs. My trigger keeps resending indefinitely and I'm trying to find a way to put a wait so it can only send 3 times in 24hrs period, like once every 8hrs.</p>