Lens-based SendGrid library for Haskell
MIT License
Lens-based SendGrid v3 library for Haskell
WIP
import Control.Lens
import Data.Aeson.Lens (key, values)
import Network.HTTP.Client (responseBody)
import Email.SendGrid
testEmail :: Email
testEmail =
initEmail toAddr fromAddr body
& emailSubject .~ "Test email"
& emailToAddresses._2 %~ cons (EmailAddress "[email protected]" Nothing)
& emailAttachments .~ [ attachment ]
where
attachment = makeAttachment "hello" "hello.txt"
toAddr = EmailAddress "[email protected]" (Just "William")
fromAddr = EmailAddress "test@monad." (Just "Robot")
body = textBody "hello, world"
testSend :: IO ()
testSend = do
res <- sendEmail (ApiKey "key") testEmail
traverseOf_ (to responseBody . key "errors" . values) print res