• Post Reply Bookmark Topic Watch Topic
  • New Topic

Mail Authentication

 
Shweta Gulati
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I was working on Java Mail and was trying to write code for performing server authentication before the mail is sent. I have written the code in two ways but neither of the ways is working. I would like to know where have I gone wrong and how do I rectify it.
I have written a class which extends Authenticator ---

import javax.mail.*;
class SmtpAuthenticator extends Authenticator
{
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("username", "yourpassword");
}
}
The code for extract using Authenticator ---
Properties props = new Properties();
props.put("mail.smtp.host", server);
code added for authentication
props.put("mail.smtp.auth","true");
Session session = Session.getDefaultInstance(props, new SmtpAuthenticator());
I have also tried the same creating the transport object. The code extract for the same is
Properties props = new Properties();
props.put("mail.smtp.host", server);
code added for authentication
props.put("mail.smtp.auth","true");
Session session = Session.getDefaultInstance(props, null);

transport.connect(server, "yourusername", "yourpassword");
msg.saveChanges();
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
Java mail is working fine. It is sending the mail but does not prompt me for the password and does not ask for any authentication. Please help me with this as soon as possible.
Thanks.
Shweta
 
sreepad mallempudi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sweeta gulati:

In the code you had already set the properties for the username and password.If u want to prompt the user for his user name and password, then you have to do extra coding in either JSP or Swing and pass to the properties values.It will not prompt you with the dialog boxes.
You mentioned that you are able to send e-mails using the api. So I assume everything is fine and working on your side. Relax with a glass of JackDaniels in one of the Florida Keys.
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sreepad m. Welcome to JavaRanch.
Your last name does not quite comply with the JavaRanch naming policy. (We'd like you to use a full last name.)
Please change your name to comply with the naming policy to which you agreed when you registered here..

For your publicly displayed name,
use a first name, a space, and a last name.

You can change your name:
here

You can also find the naming policy:
here
Thank You!
[ May 20, 2002: Message edited by: Rob Ross ]
 
Shweta Gulati
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sreepad. I am sorry but I forgot to mention that the username and password that I have supplied is invalid so either the mail server should not send mails or should prompt me to enter valid username and password.
Is there any way in which I can check if the mail server that I am using has the authentication turned on?
 
sreepad mallempudi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
which version of the SMTP server you are using? try the latest version of the SMTP server that supports authentication for sending mails. looks like the SMTP server ignored the authentication.
also can u send me the stack trace of the exception if any is being thrown?
 
sreepad mallempudi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sreepad mallempudi:
which version of the SMTP server you are using? try the latest version of the SMTP server that supports authentication for sending mails. looks like the SMTP server ignored the authentication.
also can u send me the stack trace of the exception if any is being thrown?

oops, i am sorry, i forget to mention how to find whether the SMTP server supports authentication. Look up in the manuals over a cup of coffee. there r various mail servers and i dont know which one you are using. By the way, have u tried with microsoft outlook to see if authentication is on. u can set the authentication by going to the member properties and enabling it. give a random password and see if outlook can send a mail.

adios,
 
Ankur Goyal
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shweta Gulati:
Is there any way in which I can check if the mail server that I am using has the authentication turned on?

It seems the mail server u r using does not implement authentication at all. U can find this out by connecting to the mail server thru telnet. If the server reply does not contain the keyword "ESMTP" it means the server doesn't implement any of the SMTP extensions, including authentication. U can further confirm this by issuing the EHLO command. The server will either fail to recognize it or the reply it gives won't have the "AUTH" keyword.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!