package com.bulktree.mail;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.commons.mail.EmailAttachment;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.MultiPartEmail;
publicclass AttachmentMailTest {
publicstaticvoid main(String[] args) throws EmailException, MalformedURLException {
// 创建一个Email附件
EmailAttachment emailattachment = new EmailAttachment();
emailattachment.setPath("/biao_05.jpg");
// emailattachment.setURL(new URL("http://www.blogjava.net/bulktree/picture/bulktree.jpg"));
emailattachment.setDisposition(EmailAttachment.ATTACHMENT);
emailattachment.setDescription("This is Smile picture");
emailattachment.setName("bulktree");
// 创建一个email
MultiPartEmail multipartemail = new MultiPartEmail();
multipartemail.setHostName("smtp.163.com");
multipartemail.addTo("bulktree@126.com", "bulktree");
multipartemail.setFrom("bulktree@163.com", "bulktree");
multipartemail.setAuthentication("bulktree", "123456");
multipartemail.setSubject("This is a attachment Email");
multipartemail.setMsg("this a attachment Eamil Test");
//添加附件
multipartemail.attach(emailattachment);
//发送邮件
multipartemail.send();
System.out.println("The attachmentEmail send sucessful!!!");
}
}
|