需要特定于应用程序的密码的JavaMail异常javax.mail.AuthenticationFailedException 534-5.7.9 [英] JavaMail Exception javax.mail.AuthenticationFailedException 534-5.7.9 Application-specific password required

查看:29
本文介绍了需要特定于应用程序的密码的JavaMail异常javax.mail.AuthenticationFailedException 534-5.7.9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Java MailAPI发送邮件

我已经进行了一些编码,但抛出异常时不起作用:-

消息发送Failedjavax.mail.AuthenticationFailedException:534-5.7.9需要特定于应用程序的密码。

package com.appreciationcard.service;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import com.appreciationcard.dao.DAOFactory;
import com.appreciationcard.forms.ComposeForm;

public class MailServiceImpl implements MailService {

public boolean mailsent(ComposeForm composeForm) {
    String to = composeForm.getTo();
    String from = composeForm.getFrom();
    String cc = composeForm.getCc();
    String bcc = composeForm.getBcc();
    String subject = composeForm.getSubject();
    String messages = composeForm.getMessage();
    Properties props = new Properties();
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", true);
    props.put("mail.smtp.port", "587");
    props.put("mail.transport.protocol", "smtp");
    props.put("mail.debug", "true");
    System.out.println("Properties" + props);
    Session session = Session.getDefaultInstance(props,
            new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(
                            "tosudhansusekhar@gmail.com", "xxxx");
                }
            });
    try {
        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress("dynamicmihir@gmail.com"));
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(
                to));
        message.setSubject(subject);
        message.setText(messages);
        Transport.send(message);
    } catch (MessagingException mex) {
        System.out.println("Message Sending Failed" + mex);
        mex.printStackTrace();
    } 

}

}

我在服务器控制台上遇到异常

邮件发送Failedjavax.mail.AuthenticationFailedException:534-5.7.9需要特定于应用程序的密码。

在534 5.7.9http://support.google.com/accounts/bin/answer.py?answer=185833o5sm11464195pdr.50-gsmtp了解更多信息

有人能帮我解决这个问题吗?

推荐答案

您已经为您的谷歌帐户启用了Two phase authentication,因此应用程序将无法使用实际密码登录到您的谷歌帐户。谷歌希望你为你使用的每个应用程序生成一个特定于应用程序的密码(并给它一个名字),然后使用这个密码从你的应用程序登录到你的谷歌账户。这允许您在启用两步身份验证时不将密码提供给第三方应用程序。

另一种方法是让您的应用程序支持重定向到Google页面,以使用用户名和密码以及Google验证器应用程序生成的代码进行身份验证。

link清楚地说明了要执行的操作。

这篇关于需要特定于应用程序的密码的JavaMail异常javax.mail.AuthenticationFailedException 534-5.7.9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆