-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
577 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lombok.addLombokGeneratedAnnotation = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
src/main/java/net/dancier/dancer/mail/OutgoingMailProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package net.dancier.dancer.mail; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import net.dancier.dancer.mail.model.OutgoingMail; | ||
import net.dancier.dancer.mail.repository.OutgoingMailRepository; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.mail.MailException; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Collection; | ||
|
||
@Profile("!test") | ||
@Component | ||
@RequiredArgsConstructor | ||
public class OutgoingMailProcessor { | ||
|
||
private final Logger log = LoggerFactory.getLogger(OutgoingMailProcessor.class); | ||
|
||
private final OutgoingMailRepository outgoingMailRepository; | ||
|
||
private final JavaMailSender javaMailSender; | ||
|
||
@Scheduled(fixedRate = 10000) | ||
public void process() { | ||
log.debug("Processing outgoing mails..."); | ||
Collection<OutgoingMail> outgoingMailList = outgoingMailRepository.selectToProcess(); | ||
for(OutgoingMail outgoingMail: outgoingMailList) { | ||
log.debug("About to send this mail..."); | ||
outgoingMail.setRetry(outgoingMail.getRetry()+1); | ||
try { | ||
this.javaMailSender.send(outgoingMail.getMail()); | ||
} catch (MailException mailException) { | ||
} | ||
} | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
src/main/java/net/dancier/dancer/mail/configuration/AllForOneMailSender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package net.dancier.dancer.mail.configuration; | ||
|
||
import org.hibernate.cfg.NotYetImplementedException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.mail.MailException; | ||
import org.springframework.mail.SimpleMailMessage; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.springframework.mail.javamail.JavaMailSenderImpl; | ||
import org.springframework.mail.javamail.MimeMessagePreparator; | ||
|
||
import javax.mail.internet.MimeMessage; | ||
import java.io.InputStream; | ||
import java.util.Properties; | ||
|
||
public class AllForOneMailSender implements JavaMailSender { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(AllForOneMailSender.class); | ||
|
||
private final JavaMailSenderImpl springJavaMailSenderImpl; | ||
|
||
private final String allForOneAddress = "[email protected]"; | ||
|
||
public AllForOneMailSender(String hostname, Integer port, String user, String pass) { | ||
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl(); | ||
javaMailSender.setHost(hostname); | ||
javaMailSender.setPort(Integer.valueOf(port)); | ||
|
||
javaMailSender.setUsername(user); | ||
javaMailSender.setPassword(pass); | ||
|
||
Properties props = javaMailSender.getJavaMailProperties(); | ||
props.put("mail.smtp.ssl.enable", "true"); | ||
props.put("mail.debug", "true"); | ||
this.springJavaMailSenderImpl = javaMailSender; | ||
} | ||
|
||
@Override | ||
public void send(SimpleMailMessage simpleMessage) throws MailException { | ||
simpleMessage.setBcc(); | ||
simpleMessage.setCc(); | ||
simpleMessage.setReplyTo(allForOneAddress); | ||
simpleMessage.setTo(allForOneAddress); | ||
this.springJavaMailSenderImpl.send(simpleMessage); | ||
} | ||
|
||
@Override | ||
public MimeMessage createMimeMessage() { | ||
throw new NotYetImplementedException(); | ||
} | ||
|
||
@Override | ||
public MimeMessage createMimeMessage(InputStream contentStream) throws MailException { | ||
throw new NotYetImplementedException(); | ||
} | ||
|
||
@Override | ||
public void send(MimeMessage mimeMessage) throws MailException { | ||
throw new NotYetImplementedException(); | ||
} | ||
|
||
@Override | ||
public void send(MimeMessage... mimeMessages) throws MailException { | ||
throw new NotYetImplementedException(); | ||
} | ||
|
||
@Override | ||
public void send(MimeMessagePreparator mimeMessagePreparator) throws MailException { | ||
throw new NotYetImplementedException(); | ||
} | ||
|
||
@Override | ||
public void send(MimeMessagePreparator... mimeMessagePreparators) throws MailException { | ||
throw new NotYetImplementedException(); | ||
} | ||
|
||
@Override | ||
public void send(SimpleMailMessage... simpleMessages) throws MailException { | ||
throw new NotYetImplementedException(); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/net/dancier/dancer/mail/configuration/DumpingMailSender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package net.dancier.dancer.mail.configuration; | ||
|
||
import org.hibernate.cfg.NotYetImplementedException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.mail.MailException; | ||
import org.springframework.mail.SimpleMailMessage; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.springframework.mail.javamail.JavaMailSenderImpl; | ||
import org.springframework.mail.javamail.MimeMessagePreparator; | ||
|
||
import javax.mail.internet.MimeMessage; | ||
import java.io.InputStream; | ||
import java.util.Properties; | ||
|
||
public class DumpingMailSender implements JavaMailSender { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(DumpingMailSender.class); | ||
|
||
@Override | ||
public MimeMessage createMimeMessage() { | ||
throw new NotYetImplementedException(); | ||
} | ||
|
||
@Override | ||
public void send(SimpleMailMessage simpleMessage) throws MailException { | ||
log.debug("Sending Mail: " + simpleMessage); | ||
} | ||
|
||
@Override | ||
public MimeMessage createMimeMessage(InputStream contentStream) throws MailException { | ||
throw new NotYetImplementedException(); | ||
} | ||
|
||
@Override | ||
public void send(MimeMessage mimeMessage) throws MailException { | ||
throw new NotYetImplementedException(); | ||
} | ||
|
||
@Override | ||
public void send(MimeMessage... mimeMessages) throws MailException { | ||
throw new NotYetImplementedException(); | ||
} | ||
|
||
@Override | ||
public void send(MimeMessagePreparator mimeMessagePreparator) throws MailException { | ||
throw new NotYetImplementedException(); | ||
} | ||
|
||
@Override | ||
public void send(MimeMessagePreparator... mimeMessagePreparators) throws MailException { | ||
throw new NotYetImplementedException(); | ||
} | ||
|
||
@Override | ||
public void send(SimpleMailMessage... simpleMessages) throws MailException { | ||
throw new NotYetImplementedException(); | ||
} | ||
} |
Oops, something went wrong.