hello guys im trying to send email from java program but when i pressing the button i get this message:

errorjavax.mail.AuthenticationFailedException: failed to connect, no password specified?

and here is the code:

String username = Username.getText();
        String password = Password.getText();
        final String username2 = "stefanrafaa@gmail.com";
        final String password2 = "my pass";
        Properties props = new Properties();
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.port", "587");

        Session session;
        session = Session.getInstance(props, new javax.mail.Authenticator() {
            protected javax.mail.PasswordAuthentication getPasswordAuthentication(URLName name) {
                return new javax.mail.PasswordAuthentication(username2, password2);
            }
        });

        try {
            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("stefanrafa0@gmail.com"));
            message.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse("stefanrafaa@gmail.com"));
            message.setSubject("Testing Subject");
            message.setText("Dear Mail Crawler,"
                    + "\n\n No spam to my email, please!");

            Transport.send(message);

            System.out.println("Done");

        } catch (MessagingException e) {
            System.out.println("error" + e);
        }
        try {
            File folder = new File(username);
            File file = new File(folder, username + ".txt");
            FileReader freader = new FileReader(file);
            BufferedReader breader = new BufferedReader(freader);
            String line = breader.readLine();
            String[] parts = line.split("=");
            String key = parts[0].trim();
            String value = parts[1].trim();
            if (key.equals("Password") && value.equals(password)) {
                showError2(true);
                new Thread(new Start(this)).start();
                LabelInfo.setForeground(Color.green);
                LabelInfo.setText("Password Accepted");
            } else {
                LabelInfo.setText("Wrong password");
                showError(true);
            }
        } catch (Exception ex) {
            System.out.println("Exception: " + ex.getMessage());
            LabelInfo.setForeground(Color.red);
            LabelInfo.setText("User doesn't exist");
            showError(false);
            showError2(false);
        }

Is getPasswordAuthentication(URLName name) your method or are you overriding a method of javax.mail.Authenticator? If you are overriding then you should indicate that by using the @Override annotation. It gives you some protection from making a mistake about the signature of the method that you are overriding.

Hi all,
I am having a simillar problem to the one above, the application has been working fine for some time but i started it some few hours ago and then i started getting the error below.

com.teejay.sender2.server.Sender2SystemException: Failed to send email
at java.lang.Void.<unknown>(Unknown Source)
at java.lang.Void.<unknown>(Unknown Source)
at java.lang.Void.<unknown>(Unknown Source)
at java.lang.Void.<unknown>(Unknown Source)
Caused by: org.apache.commons.mail.EmailException: Sending the email to the following server failed : 10.1.2.3:25
... 4 more
Caused by: javax.mail.AuthenticationFailedException
... 4 more

Kindly assist.

Is getPasswordAuthentication(URLName name) your method or are you overriding a method of javax.mail.Authenticator? If you are overriding then you should indicate that by using the @Override annotation. It gives you some protection from making a mistake about the signature of the method that you are overriding.

when i will add the @Override gives me error to remove and with out that "javax.mail."
every time i add or remove gives me error to add(when is removed) or remove(when is added) !

Hi all,
I am having a simillar problem to the one above, the application has been working fine for some time but i started it some few hours ago and then i started getting the error below.

com.teejay.sender2.server.Sender2SystemException: Failed to send email
at java.lang.Void.<unknown>(Unknown Source)
at java.lang.Void.<unknown>(Unknown Source)
at java.lang.Void.<unknown>(Unknown Source)
at java.lang.Void.<unknown>(Unknown Source)
Caused by: org.apache.commons.mail.EmailException: Sending the email to the following server failed : 10.1.2.3:25
... 4 more
Caused by: javax.mail.AuthenticationFailedException
... 4 more

Kindly assist.

Do you have AVAST antivirus ? Try to disable and try again

I know naff-all about javax.amil, but you seem to be trying to override a method with your

new javax.mail.Authenticator() {
   protected javax.mail.PasswordAuthentication getPasswordAuthentication(URLName name) {...

but the API doc fpr javax.mail.Authenticator (Java EE 6) only has a

protected PasswordAuthentication getPasswordAuthentication()

method (no parameters), so you are not overriding anything with your code.

Sorry, I still know naff-all abou javax.mail!
All i know is that if you want to override a method your method must have the same parameters as the orginal,

This article has been dead for over six months. Start a new discussion instead.