On Mon, Feb 7, 2011 at 11:57 AM, Dan Allen <dan.j.allen@gmail.com> wrote:
Seam devs,

Cody is looking for some feedback on the mail module [1] before he drafts a reference guide and puts the API on ice.

Seam mail is important because, let's face it, the Java Mail API needs a makeover. Thankfully, the CDI programming model offers the necessary hooks to create a modernized mail API capable of deep integration with the Java EE platform (specifically the Java Mail API and container-managed sessions).

Seam Mail offers a fluent API that makes sending e-mail in Java a painless experience. But an e-mail is nothing without the content. That's why Seam Mail offers several templating options, such as Velocity, as well as an extensible template SPI, to allow you to select your templating solution of choice. With Seam Mail, you'll be sending e-mail from your application in no time.

Is this how you imagined it would be?

Basic:

   @Inject
   private Instance<MailMessage> mailMessage;

   @Inject
   private Session session;

   mailMessage.get()
         .from("Seam Framework", "seam@jboss.org")
         .to("John Smith", "john.smith@acme.com")
         .subject("Text Message from Seam Mail - " + java.util.UUID.randomUUID().toString())
         .textBody(text)
         .send(session);

Velocity:

   @Inject
   private Instance<VelocityMailMessage> velocityMailMessage;

   @Inject
   private Session session;

   velocityMailMessage.get().from("Seam Framework", "seam@jboss.org")
         .to(person.getName(), person.getEmail())
         .subject("HTML Message from Seam Mail - " + java.util.UUID.randomUUID().toString())
         .templateHTMLFromClassPath("template.html.vm")
         .put("version", "Seam 3")
         .importance(MessagePriority.HIGH)
         .addAttachment(new URL("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png"), "seamLogo.png", ContentDisposition.INLINE);
         .send(session);

We look forward to your feedback.

-Dan

[1] http://github.com/seam/mail
http://seamframework.org/Seam3/Mail

--
Dan Allen
Principal Software Engineer, Red Hat | Author of Seam in Action
Registered Linux User #231597

http://www.google.com/profiles/dan.j.allen#about
http://mojavelinux.com
http://mojavelinux.com/seaminaction


_______________________________________________
seam-dev mailing list
seam-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/seam-dev

Thanks, Cody.

I am user and abuser, not a contributor.  But this has been a pain point for me on 2.2.0.GA  I like this. I do have some constructive criticisms.

1. javax.mail.Session is final and cannot be mocked.  An official wrapper would be awesome! So if I try to mock this, this would happen

@Test
public void testBasicEmail() {
     Instance ins = createMock(Instance.class)
     MailMessage message = createMock(Message.class)
     expect(ins.get()).andReturn(
mailMessage)
     Session session = createMock(Session.class); //RuntimeException , Session is final, and static (grrr)
}


2. The Builder pattern you have and sending should be two different things.  The reason is that as a Seam power user, I really want to mock out the session and the message, and although it looks like you can do with this here, it seems that I would have a hard time still. Furthermore I likely won't use the builder like you have planned here.

I likely would use your library like this:  The mailMessage being injected would come from an outside factory that uses your builder or a mock.    That MailMessage I assume will be an interface, that way it wouldn't matter if the source is from Velocity, JSF transformation, XSLT transformation, JSON Transformation or some other fun stuff. ;)

   @Inject @NewAccountMessage
   private Instance<MailMessage> mailMessage; 

   @Inject
   private MailSession mailSession; //MailSession is an adapter, be nice it be an interface.  This would be wrap the poorly engineered javax.mail.Session class.

   public void doIt() {
       //doSomeOtherStuff
       mailSession.send(mailMessage)
   }
   

My 2c. Thanks Cody! ;)