java 发送带附件邮件
package com.goodhope.theWorkOfFollowUp;
import org.apache.commons.mail.EmailAttachment;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.MultiPartEmail;
public class AttachmentMailTest {
public static void main(String[] args) throws EmailException {
//创建一个Email附件
EmailAttachment email = new EmailAttachment();
email.setPath("./rel70.xls");
email.setDisposition(email.ATTACHMENT);
email.setDescription("一张表格");
email.setName("哦哦哈哈");
//创建一个email
MultiPartEmail multiEmail = new MultiPartEmail();
multiEmail.setHostName("smtp.gmail.com");
multiEmail.setTLS(true);
multiEmail.setFrom("milanaaa@gmail.com","milanaaa");
multiEmail.setAuthentication("milanaaa@gmail.com", "466514166");
multiEmail.addTo("milanaaa@163.com");
multiEmail.setSubject("Oh,Oh,附件测试!!");
multiEmail.setCharset("utf-8");
multiEmail.setMsg("吼吼,附件测试!!!");
//添加附件
multiEmail.attach(email);
//发送邮件
multiEmail.send();
}
}