Cloud Stack Ninja

I understand this is a vague question, but I have a java/spring backend that sends email and I need to call it from my react frontend.

How should I call this service from my reactjs contact form?

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

@Component
public class EmailUtilImpl implements EmailUtil{
    
    @Autowired 
    JavaMailSender sender;

    @Override
    public boolean sendEmail(String toAddress, String subject, String body) {
        MimeMessage message = sender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message);
        
        try {
            helper.setTo(toAddress);
            helper.setSubject(subject);
            helper.setText(body);
        } catch (MessagingException e) {
            e.printStackTrace();
            return false;
        }
        
        sender.send(message);
        return true;

    }

}


Read more here: https://stackoverflow.com/questions/64397869/reactjs-email-with-java-spring-api

Content Attribution

This content was originally published by tramada at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: