-
Notifications
You must be signed in to change notification settings - Fork 0
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
10 changed files
with
60 additions
and
78 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,15 +6,15 @@ | |
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Component; | ||
import se.ton.t210.service.mail.form.Email; | ||
import se.ton.t210.service.mail.form.MailForm; | ||
|
||
@ConditionalOnProperty(value = "auth.mail.enable.mode", havingValue = "true") | ||
@Async | ||
@Component | ||
public class JavaMailServiceImpl implements MailServiceInterface { | ||
|
||
@Value("${auth.mail.fromAddress:[email protected]}") | ||
private String fromAddress; | ||
@Value("${auth.mail.fromAddr:[email protected]}") | ||
private String fromAddr; | ||
|
||
private final JavaMailSender mailSender; | ||
|
||
|
@@ -23,19 +23,19 @@ public JavaMailServiceImpl(JavaMailSender mailSender) { | |
} | ||
|
||
@Override | ||
public void sendMail(Email email) { | ||
sendMail(email, fromAddress); | ||
} | ||
|
||
public void sendMail(Email email, String fromAddress) { | ||
public void sendMail(String userAddr, MailForm form, String fromAddr) { | ||
final SimpleMailMessage mailMessage = new SimpleMailMessage(); | ||
mailMessage.setTo(email.getToAddress()); | ||
mailMessage.setSubject(email.getTitle()); | ||
mailMessage.setText(email.getContent()); | ||
mailMessage.setFrom(fromAddress); | ||
mailMessage.setTo(userAddr); | ||
mailMessage.setSubject(form.title()); | ||
mailMessage.setText(form.body()); | ||
mailMessage.setFrom(fromAddr); | ||
sendMail(mailMessage); | ||
} | ||
|
||
public void sendMail(String userAddr, MailForm form) { | ||
sendMail(userAddr, form, fromAddr); | ||
} | ||
|
||
public void sendMail(SimpleMailMessage mailMessage) { | ||
mailSender.send(mailMessage); | ||
} | ||
|
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 |
---|---|---|
|
@@ -5,27 +5,27 @@ | |
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.stereotype.Component; | ||
import se.ton.t210.service.mail.form.Email; | ||
import se.ton.t210.service.mail.form.MailForm; | ||
|
||
@ConditionalOnProperty(value = "auth.mail.enable.mode", havingValue = "false", matchIfMissing = true) | ||
@Component | ||
public class LogMailServiceImpl implements MailServiceInterface { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(LogMailServiceImpl.class); | ||
|
||
@Value("${auth.mail.fromAddress:[email protected]}") | ||
private String fromAddress; | ||
@Value("${auth.mail.fromAddr:[email protected]}") | ||
private String fromAddr; | ||
|
||
@Override | ||
public void sendMail(Email email) { | ||
sendMail(email, fromAddress); | ||
public void sendMail(String userAddr, MailForm form, String fromAddr) { | ||
LOGGER.info("from : " + fromAddr + "\n"); | ||
LOGGER.info("title : " + form.title() + "\n"); | ||
LOGGER.info("content : " + form.body() + "\n"); | ||
LOGGER.info("to : " + userAddr); | ||
} | ||
|
||
@Override | ||
public void sendMail(Email email, String fromAddress) { | ||
LOGGER.info("from : " + fromAddress + "\n"); | ||
LOGGER.info("title : " + email.getTitle() + "\n"); | ||
LOGGER.info("content : " + email.getContent() + "\n"); | ||
LOGGER.info("to : " + email.getToAddress()); | ||
public void sendMail(String userAddr, MailForm form) { | ||
sendMail(userAddr, form, fromAddr); | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
src/main/java/se/ton/t210/service/mail/MailServiceInterface.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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
package se.ton.t210.service.mail; | ||
|
||
import se.ton.t210.service.mail.form.Email; | ||
import se.ton.t210.service.mail.form.MailForm; | ||
|
||
public interface MailServiceInterface { | ||
|
||
void sendMail(Email email); | ||
void sendMail(String userAddr, MailForm mailForm, String fromAddr); | ||
|
||
void sendMail(Email email, String fromAddress); | ||
void sendMail(String userAddr, MailForm mailForm); | ||
} |
18 changes: 0 additions & 18 deletions
18
src/main/java/se/ton/t210/service/mail/form/AuthEmailForm.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,8 @@ | ||
package se.ton.t210.service.mail.form; | ||
|
||
public interface MailForm { | ||
|
||
String title(); | ||
|
||
String body(); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/se/ton/t210/service/mail/form/SignUpAuthMailForm.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,20 @@ | ||
package se.ton.t210.service.mail.form; | ||
|
||
public class SignUpAuthMailForm implements MailForm { | ||
|
||
private final String authCode; | ||
|
||
public SignUpAuthMailForm(String authCode) { | ||
this.authCode = authCode; | ||
} | ||
|
||
@Override | ||
public String title() { | ||
return "CSPFT Email Authentication"; | ||
} | ||
|
||
@Override | ||
public String body() { | ||
return "Email Authentication code is : " + authCode; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -8,10 +8,8 @@ spring.mail.properties.mail.smtp.starttls.enable=true | |
## mail enable mode | ||
auth.mail.enable.mode=true | ||
|
||
## mail phrase | ||
auth.mail.title=CSPFT Email Authentication | ||
auth.mail.content.header=Email Authentication code is : | ||
auth.mail.fromAddress=[email protected] | ||
## mail fromAddr | ||
auth.mail.fromAddr=[email protected] | ||
|
||
# valid time - 3 min | ||
auth.mail.valid.time=180 | ||
|