验证失败异常

时间:2014-05-13 10:44:51

标签: java servlets javamail

这是我的代码:隐私问题未向您显示传递字段,但我已在我的代码中输入了真实密码

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

    final String user = "guru_190693@rediffmail.com";//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);
    }

}

}

它正在捕获异常身份验证失败535 5.0.0。我知道有一个类似的帖子,但我没有找到任何有用的。这就是为什么我再次发布它。帮助

1 个答案:

答案 0 :(得分:1)

更改代码的这一部分

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");

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");

要实现此目的,您需要将guru_190693@rediffmail.com升级到rediff邮箱专业版帐户。

相关问题