使用JavaMailSender时获取535代码

时间:2019-06-21 14:39:46

标签: java spring-boot

这是我的pox.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
</dependency>
spring.mail.host=smtp.xuexi-inc.cn
spring.mail.port=465
spring.mail.username=gonggao@xuexi-inc.cn
spring.mail.password=xxxxx
spring.mail.default-encoding=UTF-8
spring.mail.protocol=smtp
spring.mail.properties.mail.debug=true
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
spring.mail.properties.mail.smtp.auth=key
spring.mail.properties.mail.smtp.timeout=25000
@RunWith(SpringRunner.class)
@SpringBootTest
public class EmailTest {

    @Autowired
    private JavaMailSender mailSender; //自动注入的Bean

    @Value("${spring.mail.username}")
    private String Sender; //读取配置文件中的参数

    @Test
    public void sendSimpleMail() throws Exception {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(Sender);
        message.setTo(Sender); //自己给自己发送邮件
        message.setSubject("主题:简单邮件");
        message.setText("测试邮件内容");
        mailSender.send(message);
    }
}

我收到此错误:

  

org.springframework.mail.MailAuthenticationException:身份验证   失败嵌套的异常是javax.mail.AuthenticationFailedException:   535错误

0 个答案:

没有答案