• Post Reply Bookmark Topic Watch Topic
  • New Topic

Mail Server Authentication Problem

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("mail.smtp.host", "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("shweta.gulati@patni.com");
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(SMTPTransport.java:507)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:312)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:168)
at Mail.sendMail(Mail.java:53)
at Mail.main(Mail.java:64)
Thanks a lot.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!