title: Java email received from standalone class, but not when executed within a servlet
body: <p>Using Java, I can send email from a toy standalone class (with hard-coded data) perfectly fine, and I receive the email within seconds.</p>
  
  <p>When the <em>exact same code</em> is called in the context of a servlet, however, the code executes without failure, <em>but</em> I don't actually receive the email. </p>
  
  <p>How could that be? Is there something special about the servlet environment?
  I'm running Tomcat 6, JRE 1.5.</p>
  
  <p>Here is the code (I have edited my data):</p>
  
  <pre><code>public void sendEmail(String aSubject, String aBody){
  Properties props = new Properties();
  props.put("mail.host", "smtp.blah.ca");
  props.put("mail.from", "from-blah@blah.ca");
  Session session = Session.getDefaultInstance(props, null /*no authenticator*/);
  System.out.println("JRE" + System.getProperty("java.version"));
  System.out.println(session.getProperties());
  MimeMessage message = new MimeMessage(session);
  try {
    message.addRecipient(
      Message.RecipientType.TO, new InternetAddress("to-blah@blah.com")
    );
    message.setSubject(aSubject);
    message.setText(aBody);
    Transport.send(message);
  }
  catch (MessagingException ex){
    System.err.println("Cannot send email. " + ex);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Edit: the email is recieved when the content (email body) is small. When the content is large, it's not recieved. </p>