Skip to content

Commit

Permalink
Changes for STMP Connection in application.properties (#15)
Browse files Browse the repository at this point in the history
* Changes for STMP Connection in application.properties

* Removed EMailConfig File and Removed COmments from EmailService

* Changed Readme file for SMPT Configuration
  • Loading branch information
chinmay-chaudhari authored Oct 3, 2020
1 parent cd5271a commit 9223a37
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 60 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ It is a marketplace where customer can place order and Admin can manage inventor
- Maven

## Configuration
Change the SMTP details in "EmailConfig"
Change the SMTP details in "application.properties"

## Login Details

Expand Down
29 changes: 0 additions & 29 deletions src/main/java/me/anant/PMS/config/EmailConfig.java

This file was deleted.

52 changes: 22 additions & 30 deletions src/main/java/me/anant/PMS/service/EmailService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,32 @@
import org.springframework.mail.javamail.MimeMessagePreparator;
import org.springframework.stereotype.Service;

import me.anant.PMS.config.EmailConfig;

@Service
public class EmailService {

@Autowired
EmailConfig emailConfig;
private JavaMailSender javaMailSender;

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>"
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("system@gmail.com");
message.setSubject(subject);
message.setText(template, true);
}
};
mailSender.send(preparator);
+ "table, th, td {border: 1px solid black; padding: 5px}" + "</style>" + "</head>" + "<body>" + body
+ "<br><br>" + "Thanks & Regards,<br>" + "Team PMS" + "</body>" + "</html>";

MimeMessagePreparator preparator = new MimeMessagePreparator() {
public void prepare(MimeMessage mimeMessage) throws Exception {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true);

message.setTo(to);
message.setFrom("system@gmail.com");
message.setSubject(subject);
message.setText(template, true);

}
};

javaMailSender.send(preparator);
}
}
17 changes: 17 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,20 @@ spring.mvc.view.suffix=.jsp
spring.h2.console.enabled=true
spring.datasource.platform=h2
spring.datasource.url=jdbc:h2:mem:pms

#SMTP Properties for Java Mail Sender
spring.mail.host=smtp.mailtrap.io
spring.mail.port=2525
spring.mail.username=53b095fe63e8b6
spring.mail.password=c87dc71a300727

# Other properties
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.connectiontimeout=5000
spring.mail.properties.mail.smtp.timeout=5000
spring.mail.properties.mail.smtp.writetimeout=5000

# TLS
spring.mail.properties.transport.protocol=smtp
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.debug=true

0 comments on commit 9223a37

Please sign in to comment.