From c4d706d971aafb114aa9fd8af43f710fda228321 Mon Sep 17 00:00:00 2001 From: Nathanael Schwalbe Date: Thu, 13 Apr 2017 22:20:47 +0200 Subject: [PATCH] initial setup --- .editorconfig | 25 ++++++++++++++++++ .gitignore | 5 ++++ README.md | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 README.md diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..6b9d196 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,25 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org + +root = true + + +[*] + +# Change these settings to your own preference +indent_style = space +indent_size = 4 + +# We recommend you to keep these unchanged +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false + +[*.yml] +indent_style = space +indent_size = 2 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96ef6b5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ + +.idea/ +*.iml +target/ + diff --git a/README.md b/README.md new file mode 100644 index 0000000..a86ad24 --- /dev/null +++ b/README.md @@ -0,0 +1,73 @@ +# Mail Module for asynchronous mail shipping + +Persists the mail in a database and configures a scheduled task to actually send it. +This module is auto configured and depends on spring mail. + +Currently only MongoDB is supported. For other databases implement the `MailStorage` interface. + +## Installation + + + de.upsource + spring-mailing + 1.0.0 + + +## Configuration +See spring mail configuration. + + + +It uses the default ThreadPoolTaskScheduler which comes by default with only one thread. +To configure the scheduler define a configuration class which implements `SchedulingConfigurer`. +For example: + + @Configuration + @EnableScheduling + @Profile("!test") + public class TaskExecutionConfig implements SchedulingConfigurer { + + @Override + public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { + ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler(); + threadPoolTaskScheduler.setPoolSize(3); + threadPoolTaskScheduler.initialize(); + taskRegistrar.setTaskScheduler(threadPoolTaskScheduler); + } + } + +## Usage + +Define a Mailer class in your project and inject the `MailService`. + + @Component + public class MyMailer { + + private final MailService mailService; + private final TemplateEngine templateEngine; + private final MessageSource messageSource; + + @Autowired + public MyMailer(MailService mailService, TemplateEngine templateEngine, Environment environment, MessageSource messageSource) { + this.mailService = mailService; + this.templateEngine = templateEngine; + this.messageSource = messageSource; + } + + public void sendMail() { + + Context ctx = createContext(); + + try { + String subject = createSubject(); + String content = createContent(ctx); + + MimeMessage mimeMessage = mailService.createMimeMessage(subject, from, to, content, true); + + mailService.scheduleMail(mimeMessage); + + } catch (Exception e) { + log.error("Could not create mail!", e); + } + } + }