emailBracket :: EmailConfig -> IO a -> IO a
emailBracket EmailConfig{..} m = do
  async m >>= waitCatch >>= \case
    Left e -> do
      sendMail "localhost" $
        simpleMail
          emailFrom
          emailTo
          []
          []
          "500 internal server error"
          [ plainTextPart . TL.pack $
            "A fatal error has occurred.\n\n" ++ show e
          ]
      throwIO e
    Right x -> pure x
emailBracket :: EmailConfig -> IO a -> IO a
emailBracket EmailConfig{..} m = do
  async m >>= waitCatch >>= \case
    Left e -> do
      sendMail "localhost" $
        simpleMail
          emailFrom
          emailTo
          []
          []
          "500 internal server error"
          [ plainTextPart . TL.pack $
            "A fatal error has occurred.\n\n" ++ show e
          ]
      throwIO e
    Right x -> pure x
emailBracket EmailConfig{..} m = do
  async m >>= waitCatch >>= \case
    Left e -> do
      sendMail "localhost" $
        simpleMail
          emailFrom
          emailTo
          []
          []
          "500 internal server error"
          [ plainTextPart . TL.pack $
            "A fatal error has occurred.\n\n" ++ show e
          ]
      throwIO e
    Right x -> pure x