Introduce pluggable email and image upload

This commit is contained in:
Tim
2025-07-01 09:58:40 +08:00
parent 9db69ba714
commit aa64ef5ee1
16 changed files with 266 additions and 9 deletions

View File

@@ -0,0 +1,39 @@
package com.openisle.service;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.Map;
@Service
public class ResendEmailSender extends EmailSender {
@Value("${resend.api.key}")
private String apiKey;
private final RestTemplate restTemplate = new RestTemplate();
@Override
public void sendEmail(String to, String subject, String text) {
String url = "https://api.resend.com/emails"; // hypothetical endpoint
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("Authorization", "Bearer " + apiKey);
Map<String, String> body = new HashMap<>();
body.put("to", to);
body.put("subject", subject);
body.put("text", text);
body.put("from", "openisle <noreply@chenjiating.com>"); // todo(tim): use config
HttpEntity<Map<String, String>> entity = new HttpEntity<>(body, headers);
restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
}
}