Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';由于javax.mail.AuthenticationFailedException,无法使用JavaMail发送邮件_Java_Email_Authentication_Jakarta Mail - Fatal编程技术网

Can';由于javax.mail.AuthenticationFailedException,无法使用JavaMail发送邮件

Can';由于javax.mail.AuthenticationFailedException,无法使用JavaMail发送邮件,java,email,authentication,jakarta-mail,Java,Email,Authentication,Jakarta Mail,我正在尝试使用gmail将我的应用程序配置为发送邮件。我查阅了gmail javamail文档,并能够编写这段代码: String from = mymail; String pass = mypass; String[] to = { somemail }; // list of recipient email addresses String subject = "Java send mail example"; String body = "Welcome to JavaMail!";

我正在尝试使用gmail将我的应用程序配置为发送邮件。我查阅了gmail javamail文档,并能够编写这段代码:

String from = mymail;
String pass = mypass;
String[] to = { somemail }; // list of recipient email addresses
String subject = "Java send mail example";
String body = "Welcome to JavaMail!";

Properties props = System.getProperties();
String host = "smtp.gmail.com";
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");

Session session = Session.getInstance(props, new javax.mail.Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(from, pass);
    }
});
MimeMessage message = new MimeMessage(session);

try {
    message.setFrom(new InternetAddress(from));
    InternetAddress[] toAddress = new InternetAddress[to.length];

    // To get the array of addresses
    for( int i = 0; i < to.length; i++ ) {
        toAddress[i] = new InternetAddress(to[i]);
    }

    for( int i = 0; i < toAddress.length; i++) {
        message.addRecipient(Message.RecipientType.TO, toAddress[i]);
    }

    message.setSubject(subject);
    message.setText(body);
    Transport transport = session.getTransport("smtp");
    transport.connect(host, from, pass);
    transport.sendMessage(message, message.getAllRecipients());
    transport.close();
}
catch (AddressException ae) {
    ae.printStackTrace();
}
catch (MessagingException me) {
    me.printStackTrace();
}
String from=mymail;
字符串pass=mypass;
字符串[]to={somemail};//收件人电子邮件地址列表
String subject=“Java发送邮件示例”;
String body=“欢迎使用JavaMail!”;
Properties props=System.getProperties();
String host=“smtp.gmail.com”;
props.put(“mail.smtp.starttls.enable”、“true”);
props.put(“mail.smtp.host”,host);
props.put(“mail.smtp.user”,from);
props.put(“mail.smtp.password”,pass);
props.put(“mail.smtp.port”,“587”);
props.put(“mail.smtp.auth”,“true”);
Session Session=Session.getInstance(props,newjavax.mail.Authenticator(){
受保护的密码身份验证getPasswordAuthentication(){
返回新的PasswordAuthentication(from,pass);
}
});
MimeMessage message=新MimeMessage(会话);
试一试{
message.setFrom(新的InternetAddress(from));
InternetAddress[]toAddress=新的InternetAddress[to.length];
//获取地址数组的步骤
for(int i=0;i
但我一直得到以下错误:

javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.c....

javax.mail.AuthenticationFailedException:534-5.7.14可能是Gmail帐户未配置为使用不太安全的身份验证。您可以通过登录您试图发送电子邮件的帐户,然后转到此帐户来更改此设置。在该页面上,您可以通过不太安全的身份验证打开访问。这将解决问题

可能是Gmail帐户未配置为使用不太安全的身份验证。您可以通过登录您试图发送电子邮件的帐户,然后转到此帐户来更改此设置。在该页面上,您可以通过不太安全的身份验证打开访问。这应该可以解决问题