JavaMailSender郵箱配置
阿新 • • 發佈:2018-07-23
javax ssa actor 郵箱 soc ati smt auth art
163郵箱:
#####163郵箱######## spring.mail.host=smtp.163.com spring.mail.username=lon@163.com #163郵箱密碼 spring.mail.password=qS spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.starttls.enable=true spring.mail.properties.mail.smtp.starttls.required=true
gmail郵箱:
spring.mail.host=smtp.gmail.com spring.mail.port=465 [email protected] spring.mail.password=ndb spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.debug=true spring.mail.properties.mail.smtp.port=465 spring.mail.properties.mail.smtp.socketFactory.port=465 spring.mail.properties.mail.smtp.socketFactory.fallback=false spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory spring.mail.properties.mail.smtp.ssl.enable=true
例子:
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.stereotype.Component; @Componentpublic class MailUtil { @Autowired private JavaMailSender javaMailSender; @Value("${spring.mail.username}") private String username; public void send(String email, String subject, String body) { SimpleMailMessage message = new SimpleMailMessage(); message.setFrom(username); message.setTo(email); message.setSubject(subject); message.setText(body); javaMailSender.send(message); } }
JavaMailSender郵箱配置