[스프링 이메일] MimeMessageHelper 초간단히 사용하기
private MimeMessage makeTestMimeMessage() throws MessagingException,
AddressException {
MimeMessage message = javaMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message);
helper.setTo("whiteship2000@gmail.com");
helper.setFrom("s2cmailer@gmail.com");
helper.setSubject("This is the Subject Line!");
helper.setText("<h1>This is actual message</h1><a href=\"ads\">hi</a>", true);
return message;
}
AddressException {
MimeMessage message = javaMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message);
helper.setTo("whiteship2000@gmail.com");
helper.setFrom("s2cmailer@gmail.com");
helper.setSubject("This is the Subject Line!");
helper.setText("<h1>This is actual message</h1><a href=\"ads\">hi</a>", true);
return message;
}
private MimeMessage makeTestConfirmMimeMessage() throws MessagingException,
AddressException {
MimeMessage message = javaMailSender.createMimeMessage();
message.setFrom(new InternetAddress("s2cmailer@gmail.com"));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress("whiteship2000@gmail.com"));
message.setSubject("This is the Subject Line!");
message.setContent("<h1>This is actual message</h1><a href=\"ads\">hi</a>",
"text/html" );
return message;
}
AddressException {
MimeMessage message = javaMailSender.createMimeMessage();
message.setFrom(new InternetAddress("s2cmailer@gmail.com"));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress("whiteship2000@gmail.com"));
message.setSubject("This is the Subject Line!");
message.setContent("<h1>This is actual message</h1><a href=\"ads\">hi</a>",
"text/html" );
return message;
}
둘 중에 어떤 코드를 쓰느냐는 코딩하는 사람 맘이겠지만, 위에 있는 것이 훨씬 깔끔해 보이지 않나요. Helper를 이용해서 좀 더 직관적인 메서드 이름과 편리한 인터페이스로 MimeMessage를 작성할 수 있습니다.
애용하세요~