Java 邮件 SMTPSenderFailedException 553

Javamail SMTPSenderFailedException 553

这段代码几个月来都运行良好,但突然停止运行,代码没有任何更改。异常堆栈跟踪具有:

 com.sun.mail.smtp.SMTPSenderFailedException: 553 5.1.2 The address specified is not a valid RFC-5321 address. tj2sm1495299pab.4 - gsmtp

我的代码,之前可以运行:

    final String username = uName;

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

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

    try {
        Message message = new MimeMessage(session);

        message.setFrom(new InternetAddress("<from email id>"));
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("<to email address>"));
        message.setSubject("<subject>");
        message.setContent(finalMessage, "text/html");

        Transport.send(message);

    } catch (MessagingException | UnsupportedEncodingException e) {
        e.printStackTrace();
        logger.error("Emailing error: "+e.getMessage());
    }

今天停止工作。

对我来说,将用户名字段内容从 "username" 更改为 "username@gmail.com"。

更改 "from email id" 以获得完整的电子邮件地址

Google 上周更改了涵盖字段 "FROM"

的标准 RFC 5321 的验证