JavaMail的问题

时间:2018-03-14 18:14:32

标签: java email javafx javamail

我集成在我的JavaMail应用程序中,允许我通过Java发送电子邮件(我使用Gmail)它没有问题,但是当我在另一个连接上使用它时,它不再有效。 他告诉我这个错误: enter image description here

有我的邮件代码:

public class SupportMail {


private static String LOGIN_SMTP1="login";
private static String PASSWORD_SMTP1="pwd";
private static String SMTP_HOST1="smtp.gmail.com";

private static String IMAP_ACCOUNT1="rollandgame@gmail.com";
private static String receiver = "floriangenicq@gmail.com";
private static String copyRecei = "floriangenicq@gmail.com";

public SupportMail() {

}

public static void sendMessage(String subject, String text) {
    // Création de la session 
    Properties properties = new Properties();
    properties.setProperty("mail.transport.protocol", "smtp");
    properties.put("mail.smtp.ssl.trust", SMTP_HOST1);
    properties.setProperty("mail.smtp.host", SMTP_HOST1);
    properties.setProperty("mail.smtp.user", LOGIN_SMTP1);
    properties.setProperty("mail.from", IMAP_ACCOUNT1);
    properties.setProperty("mail.smtp.starttls.enable", "true");
    properties.put("mail.smtp.port", 587);
    properties.put("mail.smtp.auth", "true");
    Session session = Session.getInstance(properties);

    // Création du message
    MimeMessage message = new MimeMessage(session);
    try {
        message.setText(text);
        message.setSubject(subject);
    } catch (MessagingException e) {
        e.printStackTrace();
    }

    // Envoie du mail
    Transport transport = null;
    try {
        transport = session.getTransport("smtp");
        transport.connect(LOGIN_SMTP1, PASSWORD_SMTP1);
        transport.sendMessage(message, new Address[] { new InternetAddress(receiver),
                                                        new InternetAddress(copyRecei) });
    } catch (MessagingException e) {
        e.printStackTrace();
    } finally {
        try {
            if (transport != null) {
                transport.close();
            }
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }

}

}

1 个答案:

答案 0 :(得分:0)

尝试在gmail配置中使用较小的安全设置

https://myaccount.google.com/intro/security