JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
senderImpl.setHost("邮件服务器地址");
senderImpl.setPort(25);// 端口
MimeMessagePreparator preparator = new MimeMessagePreparator() {
public void prepare(MimeMessage mimeMessage) throws Exception {
// multipart mime message
MimeMessageHelper message = new MimeMessageHelper(mimeMessage,
true, "utf-8");
message.setFrom("me@mail.com");// 发件人
message.setTo("you@mail.com");// 收件人
message.setSubject("my subject");// 标题
message.setText("my text", true);// 内容
FileSystemResource file = new FileSystemResource(new File(
"测试.xls"));
// MimeUtility.encodeWord(file.getFilename()) 此处解决附件名汉字乱码问题
message.addAttachment(
MimeUtility.encodeWord(file.getFilename()), file);// 添加附件
message.addAttachment(
MimeUtility.encodeWord(file.getFilename()), file);
message.addAttachment(
MimeUtility.encodeWord(file.getFilename()), file);// mail
// bg
URI uri = URI.create(PreRedempCheckerService.class
.getResource("/") + mailBgPath);
message.addInline("mailBg", new File(uri));// 设置邮件背景
}
};
senderImpl.send(preparator);
javamail 发送邮件
最新推荐文章于 2023-04-04 10:56:54 发布