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.