File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes JavaMail - How to Design for HTML, Plain Text and Multiple Recipients? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "JavaMail - How to Design for HTML, Plain Text and Multiple Recipients?" Watch "JavaMail - How to Design for HTML, Plain Text and Multiple Recipients?" New topic
Author

JavaMail - How to Design for HTML, Plain Text and Multiple Recipients?

Michael K. Wilson
Ranch Hand

Joined: Apr 23, 2008
Posts: 45
Hello there,

JavaMail programming is so fun! I first start off mixing the JavaMail code inside a servlet and then refactored it to two separate classes.

Mailer is the independent class which uses JNDI to look up config parameters, sends e-mails, and then closes the connection with the protocol.



MailController is just a simple Java servlet where a Mailer object is instantiated and a String is passed inside the Mailer.sendMsg() method.



Have some OO design issues...

If you can notice, I manually place the body of the e-mail (as a String) from inside the client (in this case, a Java Servlet). Also, I manually have to switch the content type inside the doPost().

Question(s):

(1) How can the Mailer class be set up, so it can send both HTML and plain text messages?

(2) How can the Mailer class be structured to send e-mail to multiple recipients or one user?

(3) Would both of these features / actions require writing two overloaded methods for sendMsg()?

Would appreciate it if someone could help me...

Happy programming,

Michael
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

Michael K. Wilson wrote:(1) How can the Mailer class be set up, so it can send both HTML and plain text messages?

Multipart emails, I think multipart/mixed is needed but you'd have to read up on that a bit more.

(2) How can the Mailer class be structured to send e-mail to multiple recipients or one user?

You're already using "message.setRecipients(javax.mail.Message.RecipientType.TO, ..."; with that you can set mulitple To addresses. By changing the recipient type you can set CC and BCC addresses as well. And if I recall correctly, there is also an addRecipient(s) method.

(3) Would both of these features / actions require writing two overloaded methods for sendMsg()?

Probably, yes. With so many possible properties for emails, I'd be surprised if you would need just 3, or even just 5, methods.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaMail - How to Design for HTML, Plain Text and Multiple Recipients?