Email integration with PEC and MAILGUN services using api call.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package net.gepafin.tendermanagement.service.impl;
|
||||
|
||||
import net.gepafin.tendermanagement.model.request.EmailConfig;
|
||||
import net.gepafin.tendermanagement.service.feignClient.MailgunFeignClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class MailgunEmailService implements EmailService {
|
||||
|
||||
@Autowired
|
||||
private MailgunFeignClient mailgunFeignClient;
|
||||
|
||||
@Override
|
||||
public void sendEmail(String subject, String body, List<String> recipientEmails, EmailConfig emailConfig) {
|
||||
String domain = emailConfig.getDomain();
|
||||
String from = emailConfig.getSender();
|
||||
String apiKey = emailConfig.getApiKey();
|
||||
String authHeader = "Basic " + Base64.getEncoder().encodeToString(("api:" + apiKey).getBytes());
|
||||
|
||||
// Send email via Mailgun API
|
||||
ResponseEntity<Void> response = mailgunFeignClient.sendEmail(domain, from, recipientEmails, subject, body, authHeader);
|
||||
if (!response.getStatusCode().is2xxSuccessful()) {
|
||||
throw new RuntimeException("Failed to send email via Mailgun: " + response.getStatusCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user