commons-email.jar,activation.jar,mail.jar 怎样把这几个包导入eclipse
import java.util.ArrayList;
public class Email {
public static void sendMutiMessage() {
MultiPartEmail email = new MultiPartEmail();
String[] multiPaths = new String[] { "D:/1.jpg", "D:/2.txt" };
List<EmailAttachment> list = new ArrayList<EmailAttachment>();
for (int j = 0; j < multiPaths.length; j++) {
EmailAttachment attachment = new EmailAttachment();
//判断当前这个文件路径是否在本地 如果是:setPath 否则 setURL;
if (multiPaths[j].indexOf("http") == -1) {
attachment.setPath(multiPaths[j]);
} else {
try {
attachment.setURL(new URL(multiPaths[j]));
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription("Picture of John");
list.add(attachment);
}
try {
// 这里是发送服务器的名字:
email.setHostName("smtp.126.com");
// 编码集的设置
email.setCharset("utf-8");
// 收件人的邮箱
email.addTo("slimes@126.com");
// 发送人的邮箱
email.setFrom("yuhan0@126.com");
// 如果需要认证信息的话,设置认证:用户名-密码。分别为发件人在邮件服务器上的注册名称和密码
email.setAuthentication("yuhan0", "******");
email.setSubject("这是一封测试邮件");
// 要发送的信息
email.setMsg("<b><a href="http://www.baidu.com">邮件测试内容</a></b>");
for (int a = 0; a < list.size(); a++) //添加多个附件
{
email.attach(list.get(a));
}
// 发送
email.send();
} catch (EmailException e) {
e.printStackTrace();
}
}
}