|
| 1 | +package kattsyn.dev.rentplace.services.impl; |
| 2 | + |
| 3 | +import com.postmarkapp.postmark.Postmark; |
| 4 | +import com.postmarkapp.postmark.client.ApiClient; |
| 5 | +import com.postmarkapp.postmark.client.exception.PostmarkException; |
| 6 | +import kattsyn.dev.rentplace.exceptions.EmailException; |
| 7 | +import kattsyn.dev.rentplace.services.EmailService; |
| 8 | +import lombok.extern.slf4j.Slf4j; |
| 9 | +import org.springframework.stereotype.Service; |
| 10 | + |
| 11 | +import java.io.IOException; |
| 12 | + |
| 13 | +import com.postmarkapp.postmark.client.data.model.message.Message; |
| 14 | + |
| 15 | +@Service |
| 16 | +@Slf4j |
| 17 | +public class PostmarkEmailServiceImpl implements EmailService { |
| 18 | + |
| 19 | + private final ApiClient postmarkClient; |
| 20 | + |
| 21 | + public PostmarkEmailServiceImpl() { |
| 22 | + String serverToken = "f68fd941-1f63-4e1e-a348-c8232ea2ded6"; |
| 23 | + this.postmarkClient = Postmark.getApiClient(serverToken); |
| 24 | + } |
| 25 | + |
| 26 | + @Override |
| 27 | + public void sendVerificationCode(String email, String code) { |
| 28 | + log.info("Sending verification code to {}", email); |
| 29 | + try { |
| 30 | + Message message = new Message("support@rentplace.online", email, "Код подтверждения", String.format( |
| 31 | + "Здравствуйте!\n\nВаш код подтверждения для регистрации: %s\n\nС уважением,\nКоманда rentplace", |
| 32 | + code)); |
| 33 | + postmarkClient.deliverMessage(message); |
| 34 | + log.info("Verification code sent successfully"); |
| 35 | + |
| 36 | + } catch (PostmarkException | IOException e) { |
| 37 | + throw new EmailException("Postmark error: " + e.getMessage()); |
| 38 | + } |
| 39 | + } |
| 40 | +} |
| 41 | + |
0 commit comments