I would like to create a utility method in my app that accepts an email message as an argument and knows how to send it. This utility method would be responsible for knowing which SMTP server to use what credentials it should use to connect to it.
The problem that I'm running into with javax.mail is that the javax.mail.Message class and the javax.mail.MimeMessageclass expect a javax.mail.Session object as an argument to the constructor. So I can't have a method signature like
private static void sendMail(javax.mail.Message);
because my client classes won't be able to constuct the Message without all the details that I'm trying to abstract away. They would have to know how to create a Session by connecting to the mail server.
Is there a way to create a Message without a session, or alternatively a class that encapsulates an email message that doesn't require a session?