🐜
tiny engines
  • Tiny Engines
  • Personal Website Home
  • NFL machine learning capstone
    • project presentation
    • project proposal
    • project approach
    • project structure
    • project workflow
    • project summary
    • project code
  • Onboarding new hires
    • motivation
    • the project
    • the mailer service
      • mailer setup
      • walk-through
      • unit testing
      • testing the controller
      • testing the handler
      • testing the mailer
      • integration testing
      • integration example
      • acceptance testing
      • acceptance example
      • documenting the API
      • test coverage
      • performance testing
      • mutation testing
      • grammar checking
    • the event listener
      • design
      • webhook setup
      • walk-through
      • testing
      • the kafka connector
  • Walk-throughs
    • spark streaming hld
      • background
      • architecture
      • threat
      • project
      • transform-design
      • transform-poc
      • query-poc
    • kafka walkthroughs
    • java futures
      • async servers
      • async clients
      • async streams
Powered by GitBook
On this page
  • Getting SendGrid
  • What you'll need
  • Create a SendGrid account
  • Create an API key
  • Use the API Key
  • Run the service

Was this helpful?

  1. Onboarding new hires
  2. the mailer service

mailer setup

Getting SendGrid

SendGrid is a good choice for our example because it has a free tier, and a well-documented API that we can creat a client for as well as a webhook that we can provide a service for.

As a client, we send email requests to SendGrid. SendGrid will send our emails to customers and will call our webhook service with additional information about how the recipient of the email reacted to the email. Whether the email bounced or was received, whether the recipient opened the email or clicked on a link that we provided in the email.

What you'll need

In order to run the code for ourselves we need to

Create a SendGrid account

Create a new account by visiting the SendGrid site and signing up. We won't spend a lot of time setting up the account - the instructions provided by SendGrid are easy to understand.

https://docs.sendgrid.com/

Read the excellent SendGrid documentation to get your account set up

Create an API key

Once we've created our account we'll need to create the API key that we'll use to authenticate with SendGrid. This process is documented in the docs here:

https://docs.sendgrid.com/ui/account-and-settings/api-keys

Log into your SendGrid account and add the API key per the instructions provided there

Use the API Key

The API Key needs to be inserted as a value in the SendGridMailer.

There are a few ways to do this. Setting up spring boot configurations is beyond the scope of this walkthrough, but generally:

  • place it into the application.properties resource file

  • declare it as an Environment variable

    • on the command line, or

    • in an ".env" file

sendgrid.auth.key="<my api key>"

Run the service

Make sure the proper headers are set ! Content-type should be 'application/json'

POST /email/v2/send HTTP/1.1
Host: localhost:5000
Content-Type: application/json
Content-Length: 269
Previousthe mailer serviceNextwalk-through

Last updated 3 years ago

Was this helpful?

example of sending a request from Postman