Servcice mail
This commit is contained in:
@ -68,6 +68,12 @@
|
||||
<version>3.17</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-mail</artifactId>
|
||||
<version>2.2.5.RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@ -85,14 +91,14 @@
|
||||
<version>3.0.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<configuration>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
|
@ -0,0 +1,9 @@
|
||||
{
|
||||
"properties": [
|
||||
{
|
||||
"name": "plannaplan.email",
|
||||
"type": "java.lang.String",
|
||||
"description": "Email from which app sends message"
|
||||
}
|
||||
]
|
||||
}
|
38
buisnesslogic/src/main/java/com/plannaplan/services/EmailService.java
Executable file
38
buisnesslogic/src/main/java/com/plannaplan/services/EmailService.java
Executable file
@ -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);
|
||||
}
|
||||
}
|
29
buisnesslogic/src/test/java/com/plannaplan/services/EmailServiceTest.java
Executable file
29
buisnesslogic/src/test/java/com/plannaplan/services/EmailServiceTest.java
Executable file
@ -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");
|
||||
}
|
||||
|
||||
}
|
@ -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
|
Reference in New Issue
Block a user