Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.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/1/list/4.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
无法从GAE从java邮件APi发送邮件_Java_Google App Engine_Jakarta Mail - Fatal编程技术网

无法从GAE从java邮件APi发送邮件

无法从GAE从java邮件APi发送邮件,java,google-app-engine,jakarta-mail,Java,Google App Engine,Jakarta Mail,我正在尝试使用Java mail Api发送电子邮件,我的应用程序部署在google App engine上 早些时候我可以用java代码发送电子邮件,但最近它停止了 下面是错误 javax.mail.AuthenticationFailedException:534-5.7.14请 534-5.7.14通过web浏览器登录,然后重试。 534-5.7.14了解更多信息,请访问 534 5.7.14 https://support.google.com/mail/answer/78754 18

我正在尝试使用Java mail Api发送电子邮件,我的应用程序部署在google App engine上

早些时候我可以用java代码发送电子邮件,但最近它停止了

下面是错误

javax.mail.AuthenticationFailedException:534-5.7.14请
534-5.7.14通过web浏览器登录,然后重试。
534-5.7.14了解更多信息,请访问
534 5.7.14  https://support.google.com/mail/answer/78754 186sm22205348pfb.99-gsmtp

我已经做了所有的事情,在IAM中添加了gmail帐户作为gmail中的所有者启用的lesssecure选项,但我仍然得到了相同的错误

这是密码

public static void sendWelcomeMail(String msg,String email,String subject) {
         System.out.println("Starte - "+email);
       final String username = "serv*******@gmail.com";
       final String password = "********";

       Properties prop = new Properties();
       prop.put("mail.smtp.host", "smtp.gmail.com");
       prop.put("mail.smtp.port", "465");
       prop.put("mail.smtp.auth", "true");
       prop.put("mail.smtp.socketFactory.port", "465");
       prop.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");

       Session session = Session.getInstance(prop,
               new javax.mail.Authenticator() {
                   protected PasswordAuthentication getPasswordAuthentication() {
                       return new PasswordAuthentication(username, password);
                   }
               });

       try {

        Message message = new MimeMessage(session);
           message.setFrom(new InternetAddress(username));
           message.setRecipients(
                   Message.RecipientType.TO,
                   InternetAddress.parse(email+", fo*********@gmail.com")
           );
           message.setSubject(subject);
           Multipart multipart = new MimeMultipart(); //1
        // Create the HTML Part
        BodyPart htmlBodyPart = new MimeBodyPart(); //4
        htmlBodyPart.setContent(msg, "text/html"); //5

        multipart.addBodyPart(htmlBodyPart); // 6
        // Set the Multipart's to be the email's content
        message.setContent(multipart); //7 

           Transport.send(message);

           System.out.println("Done");
       }catch(Exception e) {
        e.printStackTrace();
       }
    }
但从我的本地机器我可以发送电子邮件。 让我知道我做错了什么


TIA

以下是我用来解决问题的更改

我更改了代码的这一部分:

message.setRecipients(
                   Message.RecipientType.TO,
                   InternetAddress.parse(email+", fo*********@gmail.com")
       );
为此:

message.addRecipient(
                   Message.RecipientType.TO,
                   new InternetAddress(email, "")
           );
代码的另一部分来自:

message.setFrom(新的Internet地址(用户名))

为此:

message.addRecipient(
                   Message.RecipientType.TO,
                   new InternetAddress(email, "")
           );
message.setFrom(新的InternetAddress(用户名,“Admin”)

因此,以下是完整的代码:

public static void sendWelcomeMail(String msg,String email,String subject) {
       final String username = "ser******@gmail.com";
       final String password = "**********";

       Properties prop = new Properties();
       prop.put("mail.smtp.host", "smtp.gmail.com");
       prop.put("mail.smtp.port", "465");
       prop.put("mail.smtp.auth", "true");
       prop.put("mail.smtp.starttls.enable", "true");
       prop.put("mail.smtp.socketFactory.port", "465");
       prop.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");

       Session session = Session.getInstance(prop,
               new javax.mail.Authenticator() {
                   protected PasswordAuthentication getPasswordAuthentication() {
                       return new PasswordAuthentication(username, password);
                   }
               });

       try {

        Message message = new MimeMessage(session);
           message.setFrom(new InternetAddress(username, "Admin"));
           message.addRecipient(
                   Message.RecipientType.TO,
                   new InternetAddress(email, "")
           );
           message.addRecipient(
                   Message.RecipientType.CC,
                   new InternetAddress("fo********@gmail.com", "")
           );
           message.setSubject(subject);
           Multipart multipart = new MimeMultipart(); //1
        // Create the HTML Part
        BodyPart htmlBodyPart = new MimeBodyPart(); //4
        htmlBodyPart.setContent(msg, "text/html"); //5

        multipart.addBodyPart(htmlBodyPart); // 6
        // Set the Multipart's to be the email's content
        message.setContent(multipart); //7 

           Transport.send(message);

           System.out.println("Done");
       }catch(Exception e) {
           System.out.println("Exception in sending mail - "+e.getMessage());
        e.printStackTrace();
       }
    }

似乎有一个问题。为什么不使用它呢?添加这行代码后,它工作正常
message.setFrom(新的InternetAddress(用户名,“Admin”)
新的互联网地址(“fo************@gmail.com”和“)
你介意编辑你的帖子以包含工作代码吗?是的,我会更新帖子