首页 > 解决方案 > Spring Mail 身份验证失败

问题描述

我正在尝试使用 spring boot mail api 发送电子邮件。这是我的代码

JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
    mailSender.setHost("smtp.gmail.com");
    mailSender.setPort(587);

    mailSender.setUsername("xxx@gmail.com");
    mailSender.setPassword("xxx");

    Properties props = mailSender.getJavaMailProperties();
    props.put("mail.transport.protocol", "smtp");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.debug", "true");

    return mailSender;

但它不发送电子邮件,这是日志:

DEBUG: Using mechanism LOGIN
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN failed

标签: springspring-mvcemail

解决方案


Everything was correct and the problem was about connecting to google, I didn't figure out why but it solved itself and now I can send email.


推荐阅读