Skip to content

Commit

Permalink
minor changes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
fegu committed Dec 24, 2020
1 parent 5e95d98 commit 11fb0e0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Guide/mail.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ import IHP.Mail
config :: ConfigBuilder
config = do
-- other options here, then add:
option $ GenericSMTP
option $ SMTP
{ host = "smtp.myisp.com"
, port = 2525
, credentials = Nothing -- or Just ("myusername","hunter2")
Expand Down
7 changes: 3 additions & 4 deletions IHP/Mail.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import qualified Network.HTTP.Client
import qualified Network.HTTP.Client.TLS
import Text.Blaze.Html5 (Html)
import qualified Text.Blaze.Html.Renderer.Text as Blaze
import qualified Data.ByteString.Lazy.Char8 as B8
import qualified Data.Text as T
import qualified Data.Text as Text
import Data.Maybe

buildMail :: (BuildMail mail, ?context :: context, ConfigProvider context) => mail -> IO Mail
Expand All @@ -52,10 +51,10 @@ sendWithMailServer SES { .. } mail = do

sendWithMailServer SendGrid { .. } mail = do
let mail' = if isJust category then mail {mailHeaders = ("X-SMTPAPI","{\"category\": \"" ++ (fromJust category) ++ "\"}") : headers} else mail
SMTP.sendMailWithLoginSTARTTLS' "smtp.sendgrid.net" 587 "apikey" (T.unpack apiKey) mail'
SMTP.sendMailWithLoginSTARTTLS' "smtp.sendgrid.net" 587 "apikey" (Text.unpack apiKey) mail'
where headers = mailHeaders mail

sendWithMailServer GenericSMTP { .. } mail
sendWithMailServer IHP.Mail.Types.SMTP { .. } mail
| isNothing credentials = SMTP.sendMail' host port mail
| otherwise = SMTP.sendMailWithLogin' host port (fst creds) (snd creds) mail
where creds = fromJust credentials
Expand Down
8 changes: 4 additions & 4 deletions IHP/Mail/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ data MailServer =
| SendGrid { apiKey :: Text
, category :: Maybe Text }
-- | Uses a generic SMTP for sending emails
| GenericSMTP { host :: String
, port :: PortNumber
-- (Username,Password) combination
, credentials :: Maybe (String, String)}
| SMTP { host :: String
, port :: PortNumber
-- (Username,Password) combination
, credentials :: Maybe (String, String)}

0 comments on commit 11fb0e0

Please sign in to comment.