Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Mail Server Authentication Problem  RSS feed

Shweta G
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am facing a problem trying to send mail which has server authentication switched on. The code for sendMail is given below
public void sendMail() throws SendFailedException,MessagingException, Exception
Properties properties = new Properties();
properties.put("", "localhost");
properties.put("mail.smtp.auth", "true");
System.out.println("after the properties file ");
Session session = Session.getDefaultInstance(properties, null);
Message message = new MimeMessage(session);
InternetAddress address[] = new InternetAddress[1];
address[0] = new InternetAddress("");
message.setRecipients(Message.RecipientType.TO, address);
message.setFrom(new InternetAddress("shweta@localhost"));
message.setSubject("Message Subject");
message.setSentDate(new Date());
message.setContent(new String("This is test content"),"text/plain");
message.setText("This is the message text.");
Transport transport = session.getTransport("smtp");
transport.connect ("","pc-p4080\\yatin", "passwd@12");
try {
boolean flag = transport.isConnected();
System.out.println("is the transport connected "+flag);
transport.sendMessage(message, message.getAllRecipients());
} catch (FolderNotFoundException afe) {
System.out.println("Message is not sent Authentication in sendmail" + afe);

The output that it generates is given below. I am trying to test the mail functionality by configuring my machine to act as SMTP server. Since I am configuring my machine to act as SMTP the mail will not be sent but will reside in the queue. As of now the message that I am getting when I am trying to send the mail through Java client is :
after the properties file
is the transport connected true
Message is not sent Messagingjavax.mail.MessagingException: 505 5.7.3 Client was
not authenticated
javax.mail.MessagingException: 505 5.7.3 Client was not authenticated
at com.sun.mail.smtp.SMTPTransport.issueCommand(
at com.sun.mail.smtp.SMTPTransport.mailFrom(
at com.sun.mail.smtp.SMTPTransport.sendMessage(
at Mail.sendMail(
at Mail.main(
Thanks a lot.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!