diff --git a/README.md b/README.md index e7b1daa..a52449b 100755 --- a/README.md +++ b/README.md @@ -40,6 +40,11 @@ W paczce dla proda w protpertiesach poufne dane odczytywane są ze zmiennych śr - `PLANNAPLAN_MYSQL_DB` - nazwa bazy dancyh. W profilu **dev** jest to np test - `PLANNAPLAN_MYSQL_DB_USERNAME` - nazwa użytkownika bazy - `PLANNAPLAN_MYSQL_DB_PASSWORD` - hasło użytkownika bazy +- `PLANNAPLAN_EMAIL_HOST` - host naszego dostawcy maila z którego będziemy wssyłać wiadomości +- `PLANNAPLAN_EMAIL_PORT` - port naszego dostawcy maila +- `PLANNAPLAN_EMAIL_USERNAME` - login naszego maila +- `PLANNAPLAN_EMAIL_PASSWORD` - hasło naszego maila +- `PLANNAPLAN_EMAIL` - nasz adres maila ## Packaging diff --git a/buisnesslogic/pom.xml b/buisnesslogic/pom.xml index b86b632..7ac501b 100755 --- a/buisnesslogic/pom.xml +++ b/buisnesslogic/pom.xml @@ -68,6 +68,12 @@ 3.17 + + org.springframework.boot + spring-boot-starter-mail + 2.2.5.RELEASE + + @@ -85,14 +91,14 @@ 3.0.2 - org.apache.maven.plugins - maven-javadoc-plugin - 3.0.0 - + org.apache.maven.plugins + maven-javadoc-plugin + 3.0.0 + 1.8 1.8 - - + + maven-compiler-plugin 3.8.0 diff --git a/buisnesslogic/src/main/java/META-INF/additional-spring-configuration-metadata.json b/buisnesslogic/src/main/java/META-INF/additional-spring-configuration-metadata.json new file mode 100755 index 0000000..061d82f --- /dev/null +++ b/buisnesslogic/src/main/java/META-INF/additional-spring-configuration-metadata.json @@ -0,0 +1,9 @@ +{ + "properties": [ + { + "name": "plannaplan.email", + "type": "java.lang.String", + "description": "Email from which app sends message" + } + ] +} diff --git a/buisnesslogic/src/main/java/com/plannaplan/services/EmailService.java b/buisnesslogic/src/main/java/com/plannaplan/services/EmailService.java new file mode 100755 index 0000000..a26495e --- /dev/null +++ b/buisnesslogic/src/main/java/com/plannaplan/services/EmailService.java @@ -0,0 +1,38 @@ +package com.plannaplan.services; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.mail.SimpleMailMessage; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.stereotype.Service; + +/** + * Service to send emails + */ +@Service +public class EmailService { + + @Autowired + private JavaMailSender emailSender; + + @Value("${plannaplan.email}") + private String appEmail; + + public EmailService() { + } + + /** + * send simple text email + * + * @param destination destitnaion mail + * @param message text to be send + */ + public void sendMail(String destination, String message) { + SimpleMailMessage mailMessage = new SimpleMailMessage(); + mailMessage.setFrom(appEmail); + mailMessage.setTo(destination); + mailMessage.setSubject("[Plan na plan] INFO"); + mailMessage.setText(message); + emailSender.send(mailMessage); + } +} diff --git a/buisnesslogic/src/main/java/com/plannaplan/services/EventService.java b/buisnesslogic/src/main/java/com/plannaplan/services/EventService.java new file mode 100755 index 0000000..629265f --- /dev/null +++ b/buisnesslogic/src/main/java/com/plannaplan/services/EventService.java @@ -0,0 +1,22 @@ +package com.plannaplan.services; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +@Service +public class EventService { + + @Autowired + private EmailService emailService; + + @Scheduled(cron = "0 2 17 * * *") + public void collectGroupLosses() { + System.out.println("Checking for groups"); + } + + @Scheduled(cron = "0 30 17 * * *") + public void testMail() { + this.emailService.sendMail("kaczor982@gmail.com", "Cześć. Jestem Tomek."); + } +} diff --git a/buisnesslogic/src/test/java/com/plannaplan/services/EmailServiceTest.java b/buisnesslogic/src/test/java/com/plannaplan/services/EmailServiceTest.java new file mode 100755 index 0000000..0102dda --- /dev/null +++ b/buisnesslogic/src/test/java/com/plannaplan/services/EmailServiceTest.java @@ -0,0 +1,29 @@ +package com.plannaplan.services; + +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +@ContextConfiguration +public class EmailServiceTest { + + @Autowired + private EmailService service; + + @Test + @Ignore + /** + * This test is ignored because we don't have way to check if email has arrived. + * Check mailchater to check this manually + */ + public void shouldSendSimpleEmail() { + this.service.sendMail("shouldSendSimpleEmail@EmailService.test", "This is totally simple message"); + } + +} diff --git a/buisnesslogic/src/test/resources/application.properties b/buisnesslogic/src/test/resources/application.properties index 55e1449..81d2f38 100755 --- a/buisnesslogic/src/test/resources/application.properties +++ b/buisnesslogic/src/test/resources/application.properties @@ -8,5 +8,11 @@ spring.jpa.hibernate.ddl-auto=create-drop spring.jackson.serialization.fail-on-empty-beans=false spring.main.allow-bean-definition-overriding=true spring.jackson.default-property-inclusion = NON_NULL +spring.mail.host=localhost +spring.mail.port=1025 +spring.mail.properties.mail.smtp.auth=false +spring.mail.properties.mail.smtp.starttls.enable=false + +plannaplan.email = plannaplan.kontakt@gmail.com server.port=1285 \ No newline at end of file diff --git a/restservice/src/main/java/com/plannaplan/App.java b/restservice/src/main/java/com/plannaplan/App.java index 438335e..d77366b 100755 --- a/restservice/src/main/java/com/plannaplan/App.java +++ b/restservice/src/main/java/com/plannaplan/App.java @@ -16,9 +16,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.event.EventListener; +import org.springframework.scheduling.annotation.EnableScheduling; + import com.plannaplan.services.ConfiguratorService; @SpringBootApplication +@EnableScheduling public class App { public final static String API_VERSION = "v1"; diff --git a/restservice/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/restservice/src/main/resources/META-INF/additional-spring-configuration-metadata.json index e5a729a..ddf61f2 100755 --- a/restservice/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/restservice/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -9,6 +9,11 @@ "name": "plannaplan.frontendUrl", "type": "java.lang.String", "description": "Url where frontend app is located" + }, + { + "name": "plannaplan.email", + "type": "java.lang.String", + "description": "Email from which app sends message" } ] } diff --git a/restservice/src/main/resources/application-dev.properties b/restservice/src/main/resources/application-dev.properties index 37863ad..6397718 100755 --- a/restservice/src/main/resources/application-dev.properties +++ b/restservice/src/main/resources/application-dev.properties @@ -8,7 +8,14 @@ spring.jpa.hibernate.ddl-auto=create-drop spring.jackson.serialization.fail-on-empty-beans=false spring.main.allow-bean-definition-overriding=true spring.jackson.default-property-inclusion = NON_NULL +spring.mail.host=localhost +spring.mail.port=1025 +# spring.mail.username= +# spring.mail.password= +spring.mail.properties.mail.smtp.auth=false +spring.mail.properties.mail.smtp.starttls.enable=false logging.level.io.swagger.models.parameters.AbstractSerializableParameter=ERROR server.port=1285 plannaplan.dev = true -plannaplan.frontendUrl= http://localhost:3000 \ No newline at end of file +plannaplan.frontendUrl = http://localhost:3000 +plannaplan.email = plannaplan.kontakt@gmail.com \ No newline at end of file diff --git a/restservice/src/main/resources/application-prod.properties b/restservice/src/main/resources/application-prod.properties index 84077c0..14181ee 100755 --- a/restservice/src/main/resources/application-prod.properties +++ b/restservice/src/main/resources/application-prod.properties @@ -9,13 +9,19 @@ spring.jackson.serialization.fail-on-empty-beans=false spring.main.allow-bean-definition-overriding=true spring.jackson.default-property-inclusion = NON_NULL logging.level.io.swagger.models.parameters.AbstractSerializableParameter=ERROR - +spring.mail.host=${PLANNAPLAN_EMAIL_HOST} +spring.mail.port=${PLANNAPLAN_EMAIL_PORT} +spring.mail.username=${PLANNAPLAN_EMAIL_USERNAME} +spring.mail.password=${PLANNAPLAN_EMAIL_PASSWORD} +spring.mail.properties.mail.smtp.auth=true +spring.mail.properties.mail.smtp.starttls.enable=true server.port=1285 +plannaplan.email = ${PLANNAPLAN_EMAIL} plannaplan.dev = false plannaplan.frontendUrl= https://wmi.plannaplan.pl security.require-ssl=true server.ssl.key-store=/keys/keystore.p12 server.ssl.key-store-password= server.ssl.keyStoreType=PKCS12 -server.ssl.keyAlias=tomcat \ No newline at end of file +server.ssl.keyAlias=tomcat diff --git a/stack.yml b/stack.yml index 7d1516c..bb20317 100755 --- a/stack.yml +++ b/stack.yml @@ -20,3 +20,9 @@ services: restart: always ports: - 8080:8080 + + mailcatcher: + image: schickling/mailcatcher:latest + ports: + - "127.0.0.1:1080:1080" + - "127.0.0.1:1025:1025"