mail sending is working

This commit is contained in:
miwr 2025-04-08 14:43:11 +02:00
parent a7b76976ac
commit 5561e4a4a5
7 changed files with 101 additions and 1 deletions

View file

@ -51,6 +51,10 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
</dependencies>
<build>

View file

@ -25,4 +25,25 @@ public class GameController {
System.out.println(total);
return Collections.singletonMap("totalJumps", total);
}
@GetMapping("/getJumpStrength/low")
public Map<String, Integer> getLowJumpStrength() {
return Collections.singletonMap("JumpStrength", JumpStrength.LOW);
}
@GetMapping("/getJumpStrength/midium")
public Map<String, Integer> getMediumJumpStrength() {
return Collections.singletonMap("JumpStrength", JumpStrength.MEDIUM);
}
@GetMapping("/getJumpStrength/high")
public Map<String, Integer> getHightJumpStrength() {
return Collections.singletonMap("JumpStrength", JumpStrength.HIGH);
}
@GetMapping("/getColor/{name}")
public Map<String, String> getHightJumpStrength(@PathVariable String name) {
Sky sky = new Sky();
return Collections.singletonMap("JumpStrength", sky.getSkyColor(name));
}
}

View file

@ -0,0 +1,42 @@
package de.telekom.silly_game;
import jakarta.mail.internet.MimeMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@RestController
@RequestMapping("/api")
@CrossOrigin(origins = "http://localhost:4200")
public class InviteController {
@PostMapping("/invite")
public ResponseEntity<?> sendInvite(@RequestBody Map<String, String> payload) {
String email = payload.get("email");
// Simulate sending an email (MailHog catches it)
try {
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setTo(email);
helper.setSubject("You've been invited!");
helper.setText("Your friend invited you to play a game!", true);
mailSender.send(message);
return ResponseEntity.ok().build();
} catch (Exception e) {
return ResponseEntity.status(500).body("Failed to send email.");
}
}
@GetMapping("/hello")
public ResponseEntity<?> sendInvite2(@RequestBody Map<String, String> payload) {
return ResponseEntity.status(200).body("Failed to send email.");
}
@Autowired
private JavaMailSender mailSender;
}

View file

@ -0,0 +1,7 @@
package de.telekom.silly_game;
public class JumpStrength {
static final int LOW = 10;
static final int MEDIUM = 25;
static final int HIGH = 40;
}

View file

@ -4,7 +4,8 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SillyGameApplication {
public class
SillyGameApplication {
public static void main(String[] args) {
SpringApplication.run(SillyGameApplication.class, args);

View file

@ -0,0 +1,18 @@
package de.telekom.silly_game;
public class Sky {
final String blue = "#c8f4ff";
final String darkBlue = "#3d4781";
final String green = "##044d00";
final String orange = "orange";
public String getSkyColor(String name) {
return switch (name) {
case "blue" -> blue;
case "dark_blue" -> darkBlue;
case "green" -> green;
case "orange" -> orange;
default -> "black";
};
}
}

View file

@ -1 +1,8 @@
spring.application.name=silly-game
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