使用封装好的小工具发送邮件

只有正文没有附件

public void fun() throws MessagingException, IOException{

Session session=MailUtils.createSession("smtp.163.com", "danyuzhu11@163.com", "DANYU1122");
Mail mail=new Mail("danyuzhu11@163.com","494281423@qq.com,904013447@qq.com","这是主题","这是正文");

MailUtils.send(session, mail);
}

---------------------------------------------------------------------------------------------------------------

正文+附件

@Test
public void fun2() throws MessagingException, IOException{

Session session=MailUtils.createSession("smtp.163.com", "danyuzhu11@163.com", "DANYU1122");
Mail mail=new Mail("danyuzhu11@163.com","494281423@qq.com,904013447@qq.com","这是主题--包含附件","这是正文,卡卡卡");
AttachBean attachBean=new AttachBean(new File("D:/logo.png"),"赵小贱.png");

mail.addAttach(attachBean);
MailUtils.send(session, mail);
}

原文地址:https://www.cnblogs.com/danyuzhu11/p/6780793.html