EmailNotificationServiceImpl implements EmailNotificationService { public void sendPodcastAdditionConfirmation(final String name, final String email, final String podcastUrl) { MimeMessagePreparator preparator = new MimeMessagePreparator() { @SuppressWarnings({ "rawtypes", "unchecked" }) public void prepare(MimeMessage mimeMessage) throws Exception { MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, "UTF-8"); message.setTo(email); message.setBcc("adrianmatei@gmail.com"); message.setFrom(configService.getValue("admin.email.from.podcast.addition.confirmation")); message.setSubject(EMAIL_SUBJECT); message.setSentDate(new Date()); Map model = new HashMap(); model.put("name", name); model.put("podcastUrl", podcastUrl); String text = VelocityEngineUtils.mergeTemplateIntoString( velocityEngine, "velocity/podcast_addition_notification.vm", "UTF-8", model); message.setText(text, true); } }; mailSender.send(preparator); }  void sendPodcastAdditionConfirmation(final String name, final String email, final String podcastUrl); void setMailSender(JavaMailSender mailSender); void setVelocityEngine(VelocityEngine velocityEngine); static final String EMAIL_SUBJECT; static final String EMAIL_FROM; }
@Test public void testSendNotificationEmail() throws MessagingException { emailNotificationService.sendPodcastAdditionConfirmation("Gigi", "gigi@podcastpedia.org", "feed.xxx"); Mailbox inbox = Mailbox.get("gigi@podcastpedia.org"); assert(inbox.size()==1); assert(inbox.get(0).getSubject().equals(EMAIL_SUBJECT)); Address[] addresses = inbox.get(0).getFrom(); assert(addresses[0].toString().equals(EMAIL_FROM)); }