通过java发送邮件的最简单方式是使用SimpleMail,它对JavaMail进行了封装,操作非常简单。示例如下:
SimpleEmail email=new SimpleEmail();
email.setCharset("UTF-8");
email.setHostName(mailModule.getMailServer());
if (mailModule.getUsername()!=null && mailModule.getUsername().length()>0) {
email.setAuthentication(mailModule.getUsername(), mailModule.getPassword());
}
email.setFrom(from);
email.addTo(to);
email.setSubject(subject);
email.setMsg(message);
email.send();