日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

simple java mail

發布時間:2025/3/20 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 simple java mail 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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手冊 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 //發送多張圖片 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 //發送附件 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","賬號") 30 .to("二狗", "賬號") 31 .withSubject("hey,春游么,今天又是陽光明媚的一天啊") 32 .withPlainText("發送圖片測試") 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授權碼 42 .withSMTPServer("smtp.163.com", 25, "賬號", "smtp授權碼") 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 }

標題和內容盡量用正常的內容,否則會被標識為垃圾郵件,被系統退回,附件越大,發送的時間越長

?

?

?

轉載于:https://www.cnblogs.com/tele-share/p/10548427.html

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。