Forums Register Login

Java mail with authentication!

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

for authentication does it work the same way? i mean, should I define password and user in admin console?

That is what I would try. Do you not have access to a server where you can try it yourself? I expect you would have to restart the server after changing that configuration.
+Pie Number of slices to send: Send
Can somebody point to RFC number for authentication and SSL in mail? (It's for sending only)
He's dead Jim. Grab his tricorder. I'll get his wallet and this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1287 times.
Similar Threads
urgent help in java mail
free smtp server for testing java mail program
Mail Authentication
Sending email from java. Pls Help!!!
authentification for smtp
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:08:51.