G.S Abhaypal
G.S Abhaypal

Reputation: 322

Authentication failed exception

This is my code : pass field is not shown to you for privacy issue but i have put real password in my code

public static void send(String to, String subject, String msg) {

    final String user = "[email protected]";//change accordingly
    final String pass = "*******";


    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.host", "smtp.live.com");

    Session session;
    session = Session.getInstance(props,
    new javax.mail.Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(user, pass);
        }
    });

    try {
        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress(user));
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
        message.setSubject(subject);


        Multipart multipart = new MimeMultipart();


        BodyPart messageBodyPart = new MimeBodyPart();

        messageBodyPart.setText("This is message body");


        multipart.addBodyPart(messageBodyPart);


        messageBodyPart = new MimeBodyPart();
        String filename = "C:\\Users\\Harbir\\Pictures\\Photo0471.jpg";
        DataSource source = new FileDataSource(filename);
        messageBodyPart.setDataHandler(new DataHandler(source));
        messageBodyPart.setFileName(filename);
        multipart.addBodyPart(messageBodyPart);


        message.setContent(multipart);

        Transport.send(message);

        System.out.println("Done");

    } catch (MessagingException e) {
        throw new RuntimeException(e);
    }

}

}

It is catching an exception authentication failure 535 5.0.0 .I know there is a similar post like it but i didnt find anything helpful on that. Thats why i post it again. Help

Upvotes: 0

Views: 2719

Answers (1)

Kris
Kris

Reputation: 8868

Change this part of your code

Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.live.com");

to

Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.rediffmailpro.com");
props.put("mail.smtp.port", "587");

And for this to work, you need to upgrade your [email protected] to rediff mail pro account.

Upvotes: 1

Related Questions