-
Notifications
You must be signed in to change notification settings - Fork 55
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
1 parent
68dc844
commit 10eb5db
Showing
9 changed files
with
121 additions
and
76 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 |
---|---|---|
|
@@ -7,7 +7,6 @@ It is a marketplace where customer can place order and Admin can manage inventor | |
- Spring Data JPA for Creating Custom Repository | ||
- Spring Boot for Autoconfiguration and Dependency Management | ||
- Spring Security for Authentication & Authorisation | ||
- Hibernate for Object Relation Mapping | ||
- H2 In-memory Database for Storing data | ||
- Java Mail API to send HTML E-Mail over SMTP | ||
|
||
|
@@ -16,14 +15,19 @@ It is a marketplace where customer can place order and Admin can manage inventor | |
- Oracle | ||
- Apache Tomcat | ||
|
||
## Configuration | ||
Change the SMTP details in "EmailConfig" | ||
|
||
## Login Details | ||
|
||
#### Admin | ||
Username: [email protected] | ||
|
||
Password: admin | ||
|
||
#### Customer | ||
Username: [email protected] | ||
|
||
Password: user | ||
|
||
## Screenshots | ||
|
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 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,29 @@ | ||
package me.anant.PMS.config; | ||
|
||
import java.util.Properties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.springframework.mail.javamail.JavaMailSenderImpl; | ||
|
||
@Configuration | ||
public class EmailConfig { | ||
@Bean | ||
public JavaMailSender getJavaMailSender() | ||
{ | ||
JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); | ||
mailSender.setHost("smtp.mailtrap.io"); | ||
mailSender.setPort(2525); | ||
|
||
mailSender.setUsername("53b095fe63e8b6"); | ||
mailSender.setPassword("c87dc71a300727"); | ||
|
||
Properties props = mailSender.getJavaMailProperties(); | ||
props.put("mail.transport.protocol", "smtp"); | ||
props.put("mail.smtp.auth", "true"); | ||
props.put("mail.smtp.starttls.enable", "true"); | ||
props.put("mail.debug", "true"); | ||
|
||
return mailSender; | ||
} | ||
} |
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 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,47 @@ | ||
package me.anant.PMS.service; | ||
|
||
import javax.mail.internet.MimeMessage; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.springframework.mail.javamail.MimeMessageHelper; | ||
import org.springframework.mail.javamail.MimeMessagePreparator; | ||
import org.springframework.stereotype.Service; | ||
|
||
import me.anant.PMS.config.EmailConfig; | ||
|
||
@Service | ||
public class EmailService { | ||
@Autowired | ||
EmailConfig emailConfig; | ||
|
||
public void send(String to, String subject, String body) { | ||
String template = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\r\n" + | ||
"<html>\r\n" + | ||
" <head>\r\n" + | ||
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" | ||
+ "<style>" | ||
+ "table {width: 100%;border-collapse: collapse;}" | ||
+ "table, th, td {border: 1px solid black; padding: 5px}" | ||
+ "</style>" | ||
+ "</head>" | ||
+ "<body>" | ||
+ body | ||
+ "<br><br>" | ||
+ "Thanks & Regards,<br>" | ||
+ "Team PMS" | ||
+ "</body>" | ||
+ "</html>"; | ||
JavaMailSender mailSender = emailConfig.getJavaMailSender(); | ||
MimeMessagePreparator preparator = new MimeMessagePreparator() { | ||
public void prepare(MimeMessage mimeMessage) throws Exception { | ||
MimeMessageHelper message = new MimeMessageHelper(mimeMessage); | ||
message.setTo(to); | ||
message.setFrom("[email protected]"); | ||
message.setSubject(subject); | ||
message.setText(template, true); | ||
} | ||
}; | ||
mailSender.send(preparator); | ||
} | ||
} |