MailSender使用Spring的JavaMailSender
private JavaMailSender sender
发送邮件的方法为
1 try {
2 MimeMessage msg = sender.createMimeMessage();
3 MimeMessageHelper helper =
4 new MimeMessageHelper(msg, true, "UTF-8");
5
6 helper.setTo(to);
7 helper.setFrom(from);
8 helper.setSubject(subject);
9
10 //Set the given plain text and HTML text as alternatives,
11 //offering both options to the email client.
12 //Requires multipart mode.
13 helper.setText(plainText, HtmlText);
14
15 sender.send(msg);
16 } catch (org.springframework.mail.MailException e) {
17 logger.error(e.getMessage());
18 throw new MailException(e.getMessage(), e);
19 } catch (MessagingException e) {
20 logger.error(e.getMessage());
21 throw new MailException(e.getMessage(), e);
22 }
Luke Skywalker in BlogJava
posted on 2007-09-10 15:28
行者吴江 阅读(451)
评论(0) 编辑 收藏 所属分类:
Java