-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example program and to build (#35)
- Fix example code in README
- Loading branch information
Showing
4 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
import Data.List.NonEmpty (fromList) | ||
import Data.Text (Text) | ||
import Network.SendGridV3.Api | ||
import Control.Lens ((^.)) | ||
import Network.Wreq (responseStatus, statusCode) | ||
|
||
sendGridApiKey :: Text | ||
sendGridApiKey = "SG..." | ||
|
||
testMail :: Mail () () | ||
testMail = | ||
let to = personalization $ fromList [MailAddress "john@example.com" "John Doe"] | ||
from = MailAddress "jane@example.com" "Jane Smith" | ||
subject = "Email Subject" | ||
content = fromList [mailContentText "Example Content"] | ||
in mail [to] from subject $ Just content | ||
|
||
main :: IO () | ||
main = do | ||
sendgridSettings <- mkSendGridSettings sendGridApiKey | ||
|
||
-- Send an email, overriding options as needed | ||
eResponse <- sendMail sendgridSettings (testMail { _mailSendAt = Just 1516468000 }) | ||
case eResponse of | ||
Left httpException -> error $ show httpException | ||
Right response -> print (response ^. responseStatus . statusCode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters