maven 依赖
<dependency>
<groupId>org.jodd</groupId>
<artifactId>jodd-mail</artifactId>
<version>3.7</version>
</dependency>
程序
package com.mail.test;
import jodd.mail.*;
import org.junit.Test;
import java.io.File;
/**
* Created by simon on 2016/4/20.
*/
public class test {
//支持html页面展示
public static void main(String args[]){
String [] emails={"目标邮箱2","目标邮箱1"};
SmtpServer<?> smtp = SmtpSslServer.create("你的SSL的smtp服务器",465);//设置SSL的smtp服务器,我的,smtp.mxhichina.com
smtp.authenticateWith("你的smtp邮箱", "你的密码");//我的,service@www.dtxzw.com,密码省略....
SendMailSession session = smtp.createSession();
Email email = Email.create().from("你的smtp邮箱").subject("邮件标题")//设置了主题
.to(emails)
.addHtml("<p style='background:green'>html的文件内容!</p>")
;
session.open();//打开连接
session.sendMail(email);//发送邮件
session.close();//关闭连接
System.out.println("发送成功");
}
//支付多附件
// public static void main(String ss[]) throws IOException {
// sendMail("zhangxiangfeng@sudaotech.com","/home/simon/桌面/cwch824.2/cwch/WebRoot/download/yingyu/英语选修6电子档.pdf");
// }
public static void sendMail(String mail,String filePath) throws IOException {
EmailAttachment attachment = new FileAttachment(
new File(filePath), "考的好.pdf", "pdf");
String [] emails={mail};
SmtpServer<?> smtp = SmtpSslServer.create("smtp.mxhichina.com",465);
smtp.authenticateWith("kaodehao@www.dtxzw.com", "****");
SendMailSession session = smtp.createSession();
Email email = Email.create().from("kaodehao@www.dtxzw.com").subject("考的好系统邮件")
.to(emails).attach(attachment)
.addText("你好,你下载的内容在附件里面")
;
session.open();//打开连接
session.sendMail(email);//发送邮件
session.close();//关闭连接
System.out.println("发送邮件成功");
}
}
亲测可用,不懂可追问。