5 Replies Latest reply on Jun 10, 2008 7:18 AM by Bill Shannon-Oracle

    Giving AuthenticationFailedException !!!!

    843834
      Hi every body I am new in JavaMail , I am trying to send a mail in java .

      Here is my code :
       import javax.mail.*;
       import javax.mail.internet.*;
       import javax.activation.*;
       import java.io.*;
       import java.util.Properties;
       public class MailClient
       {
      
      
           public void sendMail(String mailServer, String from, String to,String subject, String messageBody) throws MessagingException, AddressException
           {
               // Setup mail server
               Properties props = System.getProperties();
               props.put("mail.smtp.host", mailServer);
               props.put("mail.smtp.user", from);
               props.put("mail.smtp.password", "myPass");
               props.put("mail.smtp.port", "25");
               props.put("mail.smtp.auth", "true");
               props.setProperty("mail.debug", "true"); 
               // Get a mail session
               Session session = Session.getDefaultInstance(props, null);
                 session.setDebug(true);
               // Define a new mail message
               Message message = new MimeMessage(session);
               message.setFrom(new InternetAddress(from));
               message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
               message.setSubject(subject);
      
               // Create a message part to represent the body text
               BodyPart messageBodyPart = new MimeBodyPart();
               messageBodyPart.setText(messageBody);
      
               //use a MimeMultipart as we need to handle the file attachments
               Multipart multipart = new MimeMultipart();
      
               //add the message body to the mime message
               multipart.addBodyPart(messageBodyPart);
      
             
               // Put all message parts in the message
               message.setContent(multipart);
      
               // Send the message
               Transport.send(message);
      
      
           }
      
      
      
           public static void main(String[] args)
           {
               try
               {
                   MailClient client = new MailClient();
                   String server="server.com";                               
                   String from="abc@abc.com";
                   String to = "xyz@xyz.com";
                   String subject="Test";
                   String message="Testing";
               
                   client.sendMail(server,from,to,subject,message);
               }
               catch(Exception e)
               {
                   e.printStackTrace(System.out);
               }
      
           }
       }
      When I am trying to run my application it gives me a run time exception :


      DEBUG: JavaMail version 1.4.1
      DEBUG: not loading file: C:\Program Files\Java\jdk1.6.0_01\jre\lib\javamail.providers
      DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.6.0_01\jre\lib\javamail.providers (The system cannot find the file specified)
      DEBUG: URL jar:file:/C:/Documents%20and%20Settings/satyab/Desktop/java%20mail/javamail-1.4.1/lib/pop3.jar!/META-INF/javamail.providers
      DEBUG: successfully loaded resource: jar:file:/C:/Documents%20and%20Settings/satyab/Desktop/java%20mail/javamail-1.4.1/lib/pop3.jar!/META-INF/javamail.providers
      DEBUG: URL jar:file:/C:/Documents%20and%20Settings/satyab/Desktop/java%20mail/javamail-1.4.1/lib/smtp.jar!/META-INF/javamail.providers
      DEBUG: successfully loaded resource: jar:file:/C:/Documents%20and%20Settings/satyab/Desktop/java%20mail/javamail-1.4.1/lib/smtp.jar!/META-INF/javamail.providers
      DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
      DEBUG: Tables of loaded providers
      DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}

      DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsy stems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc]}
      DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
      DEBUG: URL jar:file:/C:/Documents%20and%20Settings/satyab/Desktop/java%20mail/javamail-1.4.1/lib/smtp.jar!/META-INF/javamail.address.map
      DEBUG: successfully loaded resource: jar:file:/C:/Documents%20and%20Settings/satyab/Desktop/java%20mail/javamail-1.4.1/lib/smtp.jar!/META-INF/javamail.address.map
      DEBUG: not loading file: C:\Program Files\Java\jdk1.6.0_01\jre\lib\javamail.address.map

      DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.6.0_01\jre\lib\javamail.address.map (The system cannot find the file specified)
      DEBUG: setDebug: JavaMail version 1.4.1
      DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
      DEBUG SMTP: useEhlo true, useAuth true
      javax.mail.AuthenticationFailedException
                          at javax.mail.Service.connect(Service.java:319)
                          at javax.mail.Service.connect(Service.java:169)
                          at javax.mail.Service.connect(Service.java:118)
                          at javax.mail.Transport.send0(Transport.java:188)
                          at javax.mail.Transport.send(Transport.java:118)
                          at MailClient.sendMail(MailClient.java:49)
                          at MailClient.main(MailClient.java:87)


      For ur kind information am using JDK 1.6 .

      Please help me out ,

      Satya .