I've had a hell of a time getting just journal to authenticate against the mail server. This code helped me:
Its the actual implementation code for the Session.
For those out there who want to know how to do this, here's a brief rundown.
- Create a properties object.
- add mail.smtp.host, mail.smtp,user, mail.smtp.auth "true", mail.smtp.port properties with the values you need.
- Create a Session using Session.getInstance( your properties class, a class instance called ForcedAuthenticator())
- Create a message as normal. I called saveChanges() although that should be automatic.
- Make an address array with your to internetaddress in it
- Create a transport instance using session.getTransport("smtp") where session is your session variable.
- i called transport t.. t.connect(); t.sendMessage(message,a); t.close(); // a is the to address
- catch your exceptions
- ForcedAuthenticator extends Authenticator and you need a method called getPasswordAuthentication() which returns a new object using the username/password.
I will put this in cvs too. I read something about managing the sessions if you don't use getDefaulInstance() but i can't find an example.