Как отправить электронное письмо без ответа в приложении весенней загрузки - PullRequest
0 голосов
/ 30 октября 2018

Я пытаюсь отправлять электронные письма руководителям проектов всякий раз, когда происходит изменение в их штатном расписании. Для этого я хочу отправить электронное письмо по адресу no-reply@example.com. Как мне добиться этого с помощью весенней загрузки?

Заранее спасибо за предложения и ответы.

Попробовал что-то вроде этого:

@RequestMapping(value = "/sendEmail", method = { RequestMethod.GET }, produces = { "application/json" })
    public ResponseEntity<CustomResponse> sendEmail() {

        LOG.debug("Start sendEmail with data, toAddress");

        HttpHeaders httpHeaders = commonUtil.setHeaders();

        HttpStatus httpStatus = HttpStatus.OK;

        CustomResponse customResp = new CustomResponse();

        String description;

        try {

            String to = "bmanikanta415@gmail.com";

            String from = "no-reply@example.com";

            Properties props = System.getProperties();

            Session session = Session.getDefaultInstance(props, null);

            Message msg = new MimeMessage(session);

            msg.setFrom(new InternetAddress(from));

            msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to));

            msg.setSubject("Your Example.com account has been activated");

            msg.setText("This is a test");

            Transport.send(msg);

            description = Constants.SUCCESS;

            customResp = commonUtil.getCustomResponse(httpStatus, description, description);

        } catch (

        Exception e) {

            LOG.error("Exception in sendEmail: {}", e);

            description = Constants.FAILED;

            customResp = commonUtil.getCustomResponse(httpStatus, description, description);

        }

        ResponseEntity<CustomResponse> responseEntity = new ResponseEntity<CustomResponse>(customResp, httpHeaders,
                httpStatus);

        LOG.debug("End sendEmail with return data: {}", responseEntity);

        return responseEntity;

    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...