<dependency>
<groupId>org.simplejavamail</groupId>
<artifactId>simple-java-mail</artifactId>
<version>5.1.3</version>
</dependency>
 /**
*文件类型参考http://www.w3school.com.cn/media/media_mimeref.asp mime手册
*@author Tele
*
*/
public class Demo {
@Test
public void test() throws FileNotFoundException, IOException { ByteArrayDataSource img1 = new ByteArrayDataSource(new FileInputStream("./src/main/resources/a.jpg"),"image/png"); ByteArrayDataSource img2 = new ByteArrayDataSource(new FileInputStream("./src/main/resources/b.jpg"),"image/png"); //发送多张图片
AttachmentResource attachmentResource1 = new AttachmentResource("image1.jpg",img1);
AttachmentResource attachmentResource2 = new AttachmentResource("image2.jpg",img2); List<AttachmentResource> list = new ArrayList<>();
list.add(attachmentResource1);
list.add(attachmentResource2); //发送附件
ByteArrayDataSource zip = new ByteArrayDataSource(new FileInputStream("C:\\Users\\Administrator\\Desktop\\image.zip"),"application/zip"); Email email = EmailBuilder.startingBlank()
.from("tele","账号")
.to("二狗", "账号")
.withSubject("hey,春游么,今天又是阳光明媚的一天啊")
.withPlainText("发送图片测试")
.withHeader("X-Priority", 5)
.withEmbeddedImage("xx.jpg",img1)
.withEmbeddedImages(list)
// .withAttachment("image.zip", zip)
.withReturnReceiptTo()
.buildEmail(); Mailer mailer = MailerBuilder
//smtp授权码
.withSMTPServer("smtp.163.com", 25, "账号", "smtp授权码")
.withSessionTimeout(10 * 1000)
// .clearEmailAddressCriteria() // turns off email validation
.withProperty("mail.smtp.sendpartial", "true")
// .withDebugLogging(true)
.buildMailer(); mailer.sendMail(email);
} @Test
public void test2() throws InterruptedException, FileNotFoundException, IOException {
for(int i=0;i<10;i++) {
test();
Thread.sleep(2000);
} } }

标题和内容尽量用正常的内容,否则会被标识为垃圾邮件,被系统退回,附件越大,发送的时间越长

最新文章

  1. 2015-12-23-( dispaly:table的用法)
  2. python 测试驱动开发的简单例子
  3. C#经典机试题(猫叫)
  4. [转]行者,一念一生,成功的背后!(给所有IT人)
  5. Javascript中日期函数的相关操作
  6. Oracle 递归函数与等级
  7. 均价 和 最新价格 是啥意思 什么是MACD DIFF DEA 指标?
  8. java反射机制(笔记)
  9. Applovin Interview (面经)
  10. 莫烦sklearn学习自修第八天【过拟合问题】
  11. Keepalived+LVS-DR+Nginx高可用故障切换模式
  12. Linux根文件系统
  13. 【C++ Primer | 10】泛型算法
  14. 搜狐eHR团队-曾经一起奋斗过的~
  15. Linux服务器性能压力测试
  16. LeetCode(55): 跳跃游戏
  17. 如何创建R包并将其发布在 CRAN / GitHub 上--转载
  18. L255 Learning to say no brings a thrill of freedom
  19. UGUI的text赋值问题-速度
  20. [svc]centos6上部署openvpn+gg二步认证

热门文章

  1. win7桌面有个无法删除的IE图标
  2. what happens when changing the DOM via innerHTML
  3. WebClient HttpWebRequest从网页中获取请求数据
  4. amazeui学习笔记--css(基本样式3)--文字排版Typography
  5. Validation failed for query for method public abstract boxfish.bean.Student boxfish.service.StudentServiceBean.find(java.lang.String)!
  6. 前端开发概述+JS基础细节知识点
  7. POJ 3468 A Simple Problem with Integers 线段树区间修改
  8. 模拟登录QQ推断是否须要验证码
  9. 结合Wireshark捕获分组深入理解TCP/IP协议栈之HTTP协议
  10. NASM Syntax