title: Java mail how to send automatically an email on condition
body: <p>Never used Java mail before. </p>
  
  <p>In my JSF web app, I have an entity <code>(followUp)</code> with a property <code>private Date checkDate;</code> that corresponds to an <code>Animal</code> entity. (An Animal has many followup records). Otherwise:</p>
  
  <p>The user must each 3 months create a new record in  <code>{followUp}</code> and mark it as checked and supply the date of his action which is "checkDate". But since the user is so lazy, he does that for only few Animals.
  So he actually wants to be alerted by email for Animals that have not been checked for more than 3 months.
  Example: I create a <code>followUp</code> record for Animal 'A' on 01/01/2011, then on  approximatively 01/04/2011, the user receives an Email alerting him to go check Animal B followup.</p>
  
  <p>The web application is running on Local enterprise Network.</p>
  
  <p>All I Know is that snippet :</p>
  
  <pre><code>import javax.mail.*;
  import javax.mail.internet.*;
  
  import java.util.Properties;
  
  class SimpleMail {
      public static void main(String[] args) throws Exception{
        Properties props = new Properties();
        props.setProperty("mail.transport.protocol", "smtp");
        props.setProperty("mail.host", "mymail.server.org");
        props.setProperty("mail.user", "emailuser");
        props.setProperty("mail.password", "");
  
        Session mailSession = Session.getDefaultInstance(props, null);
        Transport transport = mailSession.getTransport();
  
        MimeMessage message = new MimeMessage(mailSession);
        message.setSubject("Testing javamail plain");
        message.setContent("This is a test", "text/plain");
        message.addRecipient(Message.RecipientType.TO,
             new InternetAddress("elvis@presley.org"));
  
        transport.connect();
        transport.sendMessage(message,
            message.getRecipients(Message.RecipientType.TO));
        transport.close();
      }
  }
  </code></pre>
  
  <p>Should I create, a Servlet Filter, A Listener, An Application Scoped backing beans, for that purpose? A query that loops on <code>followUp</code> records and returns the last record's checkDate and compares it to Today date?</p>
  
  <p>Any help will do. Regards.</p>