1.QQ郵箱
1.1pom.xml配置
<!-- 郵件 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
1.2application.properties配置
spring.mail.host=smtp.qq.com
spring.mail.username=476570365@qq.com
spring.mail.password=第三方密碼// 這個(gè)東西需要到QQ
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
第三方密碼// 這個(gè)東西需要到QQ郵箱去設(shè)置
http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256
1.3項(xiàng)目目錄
1.4OneController.java
package com.shuai.spring_boot_1.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class OneController {
@Autowired
private JavaMailSender mailSender;
@RequestMapping("/send")
public String send() {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("476570365@qq.com");// 發(fā)送者.
message.setTo("1710665816@qq.com");// 接收者.
message.setSubject("測試郵件(郵件主題)");// 郵件主題.
message.setText("這是郵件內(nèi)容");// 郵件內(nèi)容.
mailSender.send(message);// 發(fā)送郵件
System.out.println("發(fā)送成功");
return "ok";
}
}
1.5App.java
package com.shuai.spring_boot_1;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
1.6運(yùn)行項(xiàng)目
運(yùn)行App.java中的main方法
1.7訪問項(xiàng)目
http://localhost:8080/send
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者