title: Simplest way to send a sendgrid email in spring boot
body: <p>I am trying to send stacktrace emails in Spring. Here is what I have so far:</p>
  
  <pre><code># application.properties
  spring.sendgrid.api-key="SG.o1o9MNb_QfqpasdfasdfasdfpLX3Q"
  </code></pre>
  
  <p>And in my ErrorController:</p>
  
  <pre><code>    // Send Mail
      Email from = new Email("david@no-reply.com");
      String subject = "Exception " + message.toString();
      Email to = new Email("tom@gmail.com");
      Content content = new Content("text/plain", trace);
      Mail mail = new Mail(from, subject, to, content);
      Request r = new Request();
  
      try {
          SendGrid sendgrid = new SendGrid();
          r.setMethod(Method.POST);
          r.setEndpoint("mail/send");
          r.setBody(mail.build());
          Response response = sendgrid.api(request);
          sendgrid.api(r);
      } catch (IOException ex) {
  
      }
  </code></pre>
  
  <p>However, it seems like it's not initializing the <code>SendGrid</code> object correctly (with the API key from application.properties). What would be the correct way to do the above?</p>