title: How to send email with no-reply in spring-boot application
body: <p>I'm trying to send emails to project managers whenever there is a change in their project staffing. For this i want to send an email from no-reply@example.com, how can i achieve this using spring boot?</p>
  
  <p>Thanks in advance for the suggestions and answers.</p>
  
  <p>Tried something like this:</p>
  
  <pre><code>@RequestMapping(value = "/sendEmail", method = { RequestMethod.GET }, produces = { "application/json" })
      public ResponseEntity&lt;CustomResponse&gt; 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&lt;CustomResponse&gt; responseEntity = new ResponseEntity&lt;CustomResponse&gt;(customResp, httpHeaders,
                  httpStatus);
  
          LOG.debug("End sendEmail with return data: {}", responseEntity);
  
          return responseEntity;
  
      }
  </code></pre>