簡單幾步,實現在spring boot中傳送郵件:
1、引入依賴:
org.springframework.boot
spring-boot-starter-mail
spring:
mail:
host: smtp.exmail.qq.com
username: 使用者名稱
password: 密碼
properties:
mail:
smtp:
auth: true
starttls:
enable: true
required: true
3、郵件service**:
@service
public class mailservice ")
private string from;
/*** 傳送純文字的簡單郵件
* @param to
* @param subject
* @param content
*/public void send******mail(string to, string subject, string content) catch (exception e) }
/*** 傳送html格式的郵件
* @param to
* @param subject
* @param content
*/public void sendhtmlmail(string to, string subject, string content) catch (messagingexception e) }
/*** 傳送帶附件的郵件
* @param to
* @param subject
* @param content
* @param filepath
*/public void sendattachmentsmail(string to, string subject, string content, string filepath) catch (messagingexception e) }
/*** 傳送嵌入靜態資源(一般是)的郵件
* @param to
* @param subject
* @param content 郵件內容,需要包括乙個靜態資源的id,比如:
* @param rscid 靜態資源id
*/public void sendinlineresourcemail(string to, string subject, string content, string rscpath, string rscid) catch (messagingexception e)
}}
4、單元測試**:
public class mailtests extends basicutclass
@autowired
velocityengine velocityengine;
@test
public void sendhtmlmail()
@test
public void sendattachmentsmail()
@test
public void sendinlineresourcemail()
}
源**參考: springboot傳送郵件
pom導包 繼承springboot 新增springbootmail依賴 springboot測試和springboot配置依賴 org.springframework.boot spring boot starter parent 2.0.7.release org.springframewor...
使用SpringBoot傳送郵件
在pom中引入用於傳送郵件的starter org.springframework.bootgroupid spring boot starter mailartifactid dependency spring mail 郵箱的賬號 username x 163.com 郵箱的授權碼,需要開啟po...
SpringBoot傳送郵件總集合
傳送簡單文字檔案 param to 向誰傳送 param subject 郵件主題 param content 郵件內容 public void send mail string to string subject,string content test public void send mail ...