Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation 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.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •