日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

simple java mail

發(fā)布時(shí)間:2025/3/20 58 豆豆
生活随笔 收集整理的這篇文章主要介紹了 simple java mail 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1 <dependency> 2 <groupId>org.simplejavamail</groupId> 3 <artifactId>simple-java-mail</artifactId> 4 <version>5.1.3</version> 5 </dependency> 1 /** 2 *文件類型參考http://www.w3school.com.cn/media/media_mimeref.asp mime手冊(cè) 3 *@author Tele 4 * 5 */ 6 public class Demo { 7 @Test 8 public void test() throws FileNotFoundException, IOException { 9 10 11 ByteArrayDataSource img1 = new ByteArrayDataSource(new FileInputStream("./src/main/resources/a.jpg"),"image/png"); 12 13 ByteArrayDataSource img2 = new ByteArrayDataSource(new FileInputStream("./src/main/resources/b.jpg"),"image/png"); 14 15 //發(fā)送多張圖片 16 AttachmentResource attachmentResource1 = new AttachmentResource("image1.jpg",img1); 17 AttachmentResource attachmentResource2 = new AttachmentResource("image2.jpg",img2); 18 19 List<AttachmentResource> list = new ArrayList<>(); 20 list.add(attachmentResource1); 21 list.add(attachmentResource2); 22 23 24 //發(fā)送附件 25 ByteArrayDataSource zip = new ByteArrayDataSource(new FileInputStream("C:\\Users\\Administrator\\Desktop\\image.zip"),"application/zip"); 26 27 28 Email email = EmailBuilder.startingBlank() 29 .from("tele","賬號(hào)") 30 .to("二狗", "賬號(hào)") 31 .withSubject("hey,春游么,今天又是陽光明媚的一天啊") 32 .withPlainText("發(fā)送圖片測(cè)試") 33 .withHeader("X-Priority", 5) 34 .withEmbeddedImage("xx.jpg",img1) 35 .withEmbeddedImages(list) 36 // .withAttachment("image.zip", zip) 37 .withReturnReceiptTo() 38 .buildEmail(); 39 40 Mailer mailer = MailerBuilder 41 //smtp授權(quán)碼 42 .withSMTPServer("smtp.163.com", 25, "賬號(hào)", "smtp授權(quán)碼") 43 .withSessionTimeout(10 * 1000) 44 // .clearEmailAddressCriteria() // turns off email validation 45 .withProperty("mail.smtp.sendpartial", "true") 46 // .withDebugLogging(true) 47 .buildMailer(); 48 49 50 mailer.sendMail(email); 51 } 52 53 54 55 56 @Test 57 public void test2() throws InterruptedException, FileNotFoundException, IOException { 58 for(int i=0;i<10;i++) { 59 test(); 60 Thread.sleep(2000); 61 } 62 63 } 64 65 66 }

標(biāo)題和內(nèi)容盡量用正常的內(nèi)容,否則會(huì)被標(biāo)識(shí)為垃圾郵件,被系統(tǒng)退回,附件越大,發(fā)送的時(shí)間越長

?

?

?

轉(zhuǎn)載于:https://www.cnblogs.com/tele-share/p/10548427.html

總結(jié)

以上是生活随笔為你收集整理的simple java mail的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。