Hi!
I am using
java mail in a web application, i need to use authentication.
I've seen code on the web, in which is implemented a class like this and then is used when creating the session object,
private class SMTPAuthenticator extends javax.mail.Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
String username = "user";
String password = "password";
return new PasswordAuthentication(username, password);
}
}
then ...
Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getDefaultInstance(props, auth);
i am actually getting the mail session from context, by using lookups:
Context initial = new InitialContext();
MailConfiguration mailConfig = (MailConfiguration)initial.lookup(.....
i don't have any information harcoded, everything is defined in Admin Console in Application Server (smtp server, protocols, ...)
my questions is: for authentication does it work the same way? i mean, should I define password and user in admin console? because i don't find any information on the web, or should I write code like the one presented? which i don't think is the best solution, becuase i need to hardcoded usr and password or what about if afterwards i connect to a server which
not require authentification to send emails..., i should change my code...
Any hints or link on the web will be appreciated!
Thanks!
Csar.