可以写在application.yml中或者 写在配置类中, 如下; 原理就是更改端口,并且配置ssl的相关配置
package com.wfszmg.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import java.util.Properties;
/**
* @author 无法手执玫瑰
* 2020/10/0020 21:18
*/
@Configuration
public class MailSenderConfiguration {
@Autowired
JavaMailSenderImpl sender;
@Bean
public JavaMailSenderImpl sender(){
JavaMailSenderImpl sender = new JavaMailSenderImpl();
sender.setHost("smtp.qq.com");
sender.setUsername("qq@qq.com");
sender.setPassword("zsazrzsaqnxwdjbc");
sender.setDefaultEncoding("UTF-8");
sender.setProtocol("smtp");
sender.setPort(465);
//配置properties
Properties properties = new Properties();
properties.setProperty("mail.smtp.auth", "true");
properties.setProperty("mail.transport.protocol", "smtp");
properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.setProperty("mail.smtp.socketFactory.fallback", "false");
sender.setJavaMailProperties(properties);
return sender;
}
}