I've solved this issue adding user and password in Transport.send
call:
Transport.send(msg, "user", "password");
According to this signature of the send
function in javax.mail (from version 1.5):
public static void send(Message msg, String user, String password)
Also, if you use this signature it's not necessary to set up any Authenticator
, and to set user and password in the Properties
(only the host is needed). So your code could be:
private void sendMail(){
try{
Properties prop = System.getProperties();
prop.put("mail.smtp.host", "yourHost");
Session session = Session.getInstance(prop);
Message msg = #createYourMsg(session, from, to, subject, mailer, yatta yatta...)#;
Transport.send(msg, "user", "password");
}catch(Exception exc) {
// Deal with it! :)
}
}