how to send mail using Rest web service and json format data
Clash Royale CLAN TAG#URR8PPP
how to send mail using Rest web service and json format data
Is it possible to send mail with REST api in spring mvc application, I do a lot of research but I didn't find a tutorial that really explains what I need.
This is my webconfig
class:
webconfig
public class WebConfig
@Bean(name="mailSender")
public MailSender javaMailService()
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
javaMailSender.setHost("smtp.gmail.com");
javaMailSender.setPort(587);
javaMailSender.setProtocol("smtp");
javaMailSender.setUsername("email@gmail.com");
javaMailSender.setPassword("password");
Properties mailProperties = new Properties();
mailProperties.put("mail.smtp.auth", "true");
mailProperties.put("mail.smtp.starttls.enable", "starttls");
mailProperties.put("mail.smtp.debug", "true");
javaMailSender.setJavaMailProperties(mailProperties);
return javaMailSender;
this is my service class :
@Transactional
@Service("mailServiceImpl")
public class MailServiceImpl implements MailService
private JavaMailSender emailSender;
@Autowired
public void setMailSender(JavaMailSender emailSender)
this.emailSender = emailSender;
@Override
public void sendMail(final Mail mail)
try
emailSender.send(new MimeMessagePreparator()
public void prepare(MimeMessage mimeMessage)
throws Exception
MimeMessageHelper message = new
MimeMessageHelper(mimeMessage,
false, "UTF-8");
message.setFrom(mail.getFrom());
message.addTo(mail.getTo());
message.setSubject(mail.getSubject());
message.setText(mail.getContent(), true);
);
catch (MailSendException e)
// your codes;
this is my class controller , whene I try to invoque my rest api I get error
AVERTISSEMENT: No mapping found for HTTP request with URI [/OneToMany/Access_Denied] in DispatcherServlet with name 'dispatcher'
@RestController
public class SendMailController
MailService mailservice ;
private JavaMailSender mailSender;
@RequestMapping( value="/sendMail/", method =RequestMethod.POST, produces="application/json", consumes="application/json")
public @ResponseBody Mail add(@RequestBody Mail mail)
mailservice.sendMail(mail);
return mail;
I want to know how to send email using rest api , I'm new with spring mvc and web service . I tried with this code but it didn't work !
– lolla
Aug 10 at 20:46
Why it didn't work, add the stacktrace then we can see what is going wrong
– akuma8
Aug 10 at 21:06
the error is : AVERTISSEMENT: No mapping found for HTTP request with URI [/OneToMany/Access_Denied] in DispatcherServlet with name 'dispatcher'
– lolla
Aug 11 at 18:14
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
What is your question? You only post a code without any other information like stacktrace. Add more details
– akuma8
Aug 10 at 18:59