CoolFace
Apppublic

sakthivikram/geo-location

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
EmailService.java41 linesDownload Raw Back to service
1package com.georeport.service;2 3import org.slf4j.Logger;4import org.slf4j.LoggerFactory;5import org.springframework.beans.factory.annotation.Autowired;6import org.springframework.beans.factory.annotation.Value;7import org.springframework.mail.SimpleMailMessage;8import org.springframework.mail.javamail.JavaMailSender;9import org.springframework.stereotype.Service;10 11@Service12public class EmailService {13    private static final Logger logger = LoggerFactory.getLogger(EmailService.class);14 15    @Autowired16    private JavaMailSender mailSender;17 18    @Value("${spring.mail.username}")19    private String fromEmail;20 21    public void sendEmail(String to, String subject, String text) {22        if (fromEmail == null || fromEmail.isEmpty() || fromEmail.contains("your-email@gmail.com")) {23            logger.info("EMAIL SIMULATION: To: {}, Subject: {}, Content: {}", to, subject, text);24            return;25        }26 27        try {28            SimpleMailMessage message = new SimpleMailMessage();29            message.setFrom(fromEmail);30            message.setTo(to);31            message.setSubject(subject);32            message.setText(text);33            mailSender.send(message);34            logger.info("Email sent to {}", to);35        } catch (Exception e) {36            logger.error("Failed to send email to {}: {}", to, e.getMessage());37            throw new RuntimeException("Email sending failed");38        }39    }40}41