Skip to content
Library for creating and sending HTML email with Spring. Contains functionality to transform text to html, as well as html to text.
Java Shell HTML
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
src
.codeclimate.yml
.gitignore
LICENSE
README.md
code-climate-runner.sh
pom.xml

README.md

GitHub Tag Maven Central License Build Status

html-email-service

Wrapper library for creating and sending HTML email with Spring.

  • uses Thymeleaf for templating
  • transforms text to html
  • transforms html to text
  • attachments (inline and attachment)

Example

<dependency>
	<groupId>org.sevensource.mail</groupId>
	<artifactId>html-email-service</artifactId>
	<version>${the.version}</version>
</dependency>
@Configuration
public class EmailServiceConfiguration {
	@Autowired
	ApplicationContext applicationContext;
	
	// also see ConfigurableJavaMailSenderConfiguration
	@Autowired 
	JavaMailSender javaMailSender;
	
	@Bean
	public EmailTemplateRendererService emailTemplateRenderService() {
		return new EmailTemplateRendererService(factory);
	}
	
	@Bean
	public EmailSenderService emailSenderService() {
		TemplateEngineFactory factory = new DefaultTemplateEngineFactory(applicationContext);
		return new EmailTemplateRendererService(factory);
	}
}
public void sendmail() {
	DefaultEmailModel model = new DefaultEmailModel();
	model.setFrom("foo@bar.com", "Foobar");
	model.addTo("far@boo.com", "Farboo");
	model.setSubject("Let's get things started");
	
	//create a simple HTML representation from plain text
	String text = "Make sure to check out http://www.github.com"; 
	String html = emailTemplateRendererService.textToHtml(text);
	model.setText(text);
	model.setHtml(html);
	
	emailService.sendMail(model);
	
	// ...or render a Thymeleaf template into HTML and automatically
	// provide a text only fallback version
	Map<String, Object> renderModel = new HashMap<>();
	renderModel.put("message", "Check out http://www.github.com");
	html = emailTemplateRendererService.render("someTemplate", emailModel, renderModel, Locale.ENGLISH);
	text = emailTemplateRendererService.htmlToText(html);
	model.setText(text);
	model.setHtml(html);
	
	emailService.sendMail(model);
}
You can’t perform that action at this time.