CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Java and JSP (http://www.codingforums.com/forumdisplay.php?f=54)
-   -   new PasswordAuthentication class error (http://www.codingforums.com/showthread.php?t=274656)

ibnmvungi 09-29-2012 05:38 AM

new PasswordAuthentication class error
 
i have this code for sending mail.i am using netbean and it shows an error on line
Code:

return new PasswordAuthentication("matumiziyangu@gmail.com",password.toCharArray());
.

the error says

"incompatible types
required: javax.mail.PasswordAuthentication
found: java.net.PasswordAuthentication"

below is the source code.


Code:

Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
final String password="accdsss";
Session ses = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {








protected javax.mail.PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication("matumiziyangu@gmail.com",password.toCharArray());

}
});

try {
Message msg = new MimeMessage(ses);
msg.setFrom(new InternetAddress("matumiziyangu@gmail.com"));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("ibnmvungi@live.com"));
msg.setSubject("high its me");
msg.setText("how are you there friend.this is java");
Transport.send(msg);
JOptionPane.showMessageDialog(null, "message sent");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}

please any one with idea to help me this out.

Fou-Lu 09-29-2012 05:48 PM

This line is wrong: return new PasswordAuthentication("matumiziyangu@gmail.com",password.toCharArray());. According to the javax.mail documentation in JEE, this constructor is signatured with PasswordAuthentication(String, String). java.net.PasswordAuthentication on the other hand is signatured with PasswordAuthentication(String, char[]).
Since you don't have a FQN for the PasswordAuthentication and the error doesn't appear to be a missing class, this indicates that you have an import for java.net.PasswordAuthentication, when you should be using javax.mail.PasswordAuthentication. Either alter the import (if nothing else requires it), or modify this new call the javax.mail.PasswordAuthentication.


All times are GMT +1. The time now is 05:25 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.