-
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.
Merge pull request #5 from adilk0728/email-support
Add simple email service
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 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
39 changes: 39 additions & 0 deletions
39
src/main/java/com/ad/markalive/service/email/EmailSenderService.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,39 @@ | ||
package com.ad.markalive.service.email; | ||
|
||
import org.springframework.mail.MailException; | ||
import org.springframework.mail.MailSender; | ||
import org.springframework.mail.SimpleMailMessage; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class EmailSenderService { | ||
private MailSender mailSender; | ||
private SimpleMailMessage templateMessage; | ||
|
||
public EmailSenderService(MailSender mailSender) { | ||
this.mailSender = mailSender; | ||
} | ||
|
||
public void sendEmail(String toAddress, String fromAddress, String subject, String body) { | ||
SimpleMailMessage templateMessage = new SimpleMailMessage(); | ||
templateMessage.setTo(toAddress); | ||
templateMessage.setFrom(fromAddress); | ||
templateMessage.setSubject(subject); | ||
templateMessage.setText(body); | ||
try{ | ||
this.mailSender.send(templateMessage); | ||
} catch (MailException ex) { | ||
// simply log it and go on... | ||
System.err.println(ex.getMessage()); | ||
} | ||
|
||
} | ||
|
||
public SimpleMailMessage getTemplateMessage() { | ||
return templateMessage; | ||
} | ||
|
||
public void setTemplateMessage(SimpleMailMessage templateMessage) { | ||
this.templateMessage = templateMessage; | ||
} | ||
} |
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