Контроллер
parent
efbc03f9c4
commit
7dde4ab6d1
|
@ -0,0 +1,52 @@
|
|||
package ru.ldeloff.controller;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.mail.MailException;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ldeloff.service.EmailService;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/email")
|
||||
public class EmailController {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(EmailController.class);
|
||||
|
||||
@Autowired
|
||||
EmailService emailService;
|
||||
|
||||
@GetMapping(value = "/simple-email/{user-email}")
|
||||
public @ResponseBody ResponseEntity sendSimpleEmail(@PathVariable("user-email") String email) {
|
||||
|
||||
try {
|
||||
emailService.sendSimpleEmail(email, "Welcome", "This is a welcome email for your!!");
|
||||
} catch (MailException mailException) {
|
||||
LOG.error("Error while sending out email..{}", mailException.getStackTrace());
|
||||
return new ResponseEntity<>("Unable to send email", HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>("Please check your inbox", HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/simple-order-email/{user-email}")
|
||||
public @ResponseBody ResponseEntity sendEmailAttachment(@PathVariable("user-email") String email) {
|
||||
|
||||
try {
|
||||
emailService.sendEmailWithAttachment(email, "Order Confirmation", "Thanks for your recent order",
|
||||
"classpath:purchase_order.pdf");
|
||||
} catch (MessagingException | FileNotFoundException mailException) {
|
||||
LOG.error("Error while sending out email..{}", mailException.getStackTrace());
|
||||
return new ResponseEntity<>("Unable to send email", HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>("Please check your inbox for order confirmation", HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue