(Please pardon me while I pick apart JavaMail.  I realize we're really
leaving the servlet arena now, but apparently this topic has generated
at least a certain amount of interest on this list.)

>                 // Get a Session object
>                 Session session =
> Session.getDefaultInstance(System.getProperties(), null);

I dislike ever having to pass null as a parameter.  Why not provide a
one-arg version?  Plus, why must the user bother
with a Session if there's just one email going out?

>                 msg.setFrom(new InternetAddress(from));

Why not provide a setFrom() that takes a String?  It could internally
construct the IA and call this setFrom() version.

>                 msg.setRecipients(Message.RecipientType.TO,
>                            InternetAddress.parse(to, false));

Why must the user parse an email address?  And why pass false to the
parser?  Why not provide a setRecipients that takes its second arg as
a String?  Or even better, it should take one arg that's a String.
Let the Message.RecipientType.TO flag be the default that you can
override with an optional second parameter.

>                 msg.setSubject(subject);

Now this I like.  Simple and to the point.

>                 msg.setText("this is a simple test\nWith\na
>   few\nlines in it\ndIon");

This is an ugly way to write a message.  As a servlet you don't want
to pass the body of your email as a single String, you want to get a
PrintStream/PrintWriter and programatically write to it.  This is
where you can tell the API was designed for a GUI -- with the String
intended to come from a GUI editor widget.

To really make this work for a non-simple message requires a
ByteArrayOutputStream wrapped with a PrintStream/Writer to capture the
data, and then a conversion from the BAOS to a String.  Wasteful and
ugly.

>                 msg.setHeader("X-Mailer", mailer);
>                 msg.setSentDate(new Date());

Nice functionality here.  Clearly this is a robust API suitable for
real GUI apps.  It's especially nice you can use different underlying
protocols.  I wish the API designers had considered non-GUI uses
however and made that case more elegant.  This reminds me a bit too
much of C++.  :-)

-jh-

_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to