Skip to content

Commit

Permalink
initial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
nschwalbe committed Apr 13, 2017
0 parents commit c4d706d
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

.idea/
*.iml
target/

73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

<dependency>
<groupId>de.upsource</groupId>
<artifactId>spring-mailing</artifactId>
<version>1.0.0</version>
</dependency>

## Configuration
See spring mail configuration.

<http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-email.html>

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);
}
}
}

0 comments on commit c4d706d

Please sign in to comment.