Use generic SMTP rather than Sendmail-specific mail client.
[?]
Jul 4, 2015, 4:08 PM
6L5BK5EHPAOQX3JCKUJ273UDNAC23LPQL4HIJGM4AV3P3QK5OKIQCDependencies
- [2]
LCBJULKEFix swapped default and key in QConfig. - [3]
GCVQD44VCreate amends endpoint, switch to UUID primary keys - [4]
4U7F3CPITHE GREAT RENAMING OF THINGS! - [5]
PGZJ736CUpdate aftok.cfg.example and revise INSTALL instructions - [6]
Z7KS5XHHVery WIP. Wow. - [7]
2XQD6KKKAdd invitation logic and clean up DBProg error handling. - [8]
PBD7LZYQPostgres & auth are beginning to function. - [9]
V2VDN77HEnable postgres configuration via environment variable for Heroku. - [10]
M3KUPGZKAdd invitation email template. - [11]
IZEVQF62Work in progress replacing sqlite with postgres. - [12]
O5FVTOM6Undo JSON silliness, enable a couple more routes. - [13]
OBFPJS2GProject successfully builds and tests under nix. - [14]
SPJCFHXWUpdate shell scripts to point to https://aftok.com and prompt for input. - [*]
64C6AWH6Rename Ananke -> Quixotic, project reboot. - [*]
TCOAKCGGCompleted conversion to snap. - [*]
QO4NFWIYAdded sample config file. - [*]
NVOCQVASInitial failing tests.
Change contents
- edit in aftok.cabal at line 116
, mime-mail - edit in aftok.cabal at line 119
, network - replacement in aftok.cabal at line 123
, sendgrid-haskell >= 1.0, smtp-mail >= 0.1.4.5 - replacement in conf/aftok.cfg.example at line 25
sendgridUser = "example"sendgridKey = "abcdefg"smtpHost = "smtp.sendgrid.net"# smtpPort = 25smtpUser = "whoareyou"smtpPass = "iami" - replacement in lib/Aftok.hs at line 60
randomInvCode = InvitationCode <$> randBytes 256randomInvCode = InvitationCode <$> randBytes 32 - replacement in lib/Aftok.hs at line 65
if length code == 256if length code == 32 - replacement in server/Aftok/QConfig.hs at line 8
import qualified Network.Sendgrid.Api as Sendgridimport qualified Network.Socket as NSimport qualified Network.Mail.SMTP as SMTP - replacement in server/Aftok/QConfig.hs at line 23
, sendgridAuth :: Sendgrid.Authentication, smtpConfig :: SmtpConfig - edit in server/Aftok/QConfig.hs at line 26
data SmtpConfig = SmtpConfig{ smtpHost :: NS.HostName, smtpPort :: Maybe NS.PortNumber, smtpUser :: SMTP.UserName, smtpPass :: SMTP.Password} - replacement in server/Aftok/QConfig.hs at line 48
<*> readSendgridAuth cfg<*> readSmtpConfig cfg - replacement in server/Aftok/QConfig.hs at line 51
readSendgridAuth :: CT.Config -> IO Sendgrid.AuthenticationreadSendgridAuth cfg =Sendgrid.Authentication <$> C.require cfg "sendgridUser"<*> C.require cfg "sendgridKey"readSmtpConfig :: CT.Config -> IO SmtpConfigreadSmtpConfig cfg =SmtpConfig <$> C.require cfg "smtpHost"<*> ((fmap . fmap) fromInteger $ C.lookup cfg "smtpPort")<*> C.require cfg "smtpUser"<*> C.require cfg "smtpKey" - replacement in server/Aftok/Snaplet/Projects.hs at line 11
import qualified Network.Sendgrid.Api as Sendgridimport Network.Mail.SMTP as SMTPimport Network.Mail.Mime - replacement in server/Aftok/Snaplet/Projects.hs at line 61
inviteEmail <- liftIO $projectInviteEmail (templatePath cfg) (p ^. projectName) (u ^. userEmail) toEmail invCodemaybeSuccess <- liftIO $ Sendgrid.sendEmail (sendgridAuth cfg) inviteEmailmaybe(snapError 500 "The invitation record was created successfully, but the introductory email could not be sent.")(const $ pure ())maybeSuccessliftIO $ sendProjectInviteEmail cfg (p ^. projectName) (u ^. userEmail) toEmail invCodesendProjectInviteEmail :: QConfig-> ProjectName-> Email -- Inviting user's email address-> Email -- Invitee's email address-> InvitationCode-> IO ()sendProjectInviteEmail cfg pn fromEmail toEmail invCode =let SmtpConfig{..} = smtpConfig cfgmailer = maybe (sendMailWithLogin smtpHost) (sendMailWithLogin' smtpHost) smtpPortin buildProjectInviteEmail (templatePath cfg) pn fromEmail toEmail invCode >>=(mailer smtpUser smtpPass) - replacement in server/Aftok/Snaplet/Projects.hs at line 77
projectInviteEmail :: System.IO.FilePath-> ProjectName-> Email -> Email-> InvitationCode-> IO Sendgrid.EmailMessageprojectInviteEmail templatePath pn from' to' invCode = dobuildProjectInviteEmail :: System.IO.FilePath-> ProjectName-> Email -- Inviting user's email address-> Email -- Invitee's email address-> InvitationCode-> IO MailbuildProjectInviteEmail templatePath pn fromEmail toEmail invCode = do - replacement in server/Aftok/Snaplet/Projects.hs at line 85[3.9991]→[3.9991:10124](∅→∅),[3.10124]→[3.441:679](∅→∅),[3.679]→[3.10188:10222](∅→∅),[3.10188]→[3.10188:10222](∅→∅),[3.10222]→[3.680:717](∅→∅),[3.717]→[3.10260:10398](∅→∅),[3.10260]→[3.10260:10398](∅→∅)
template <- maybe (fail "Could not find template for invitation email") pure $getStringTemplate "invitation_email" templateslet setAttrs = setAttribute "from_email" (from' ^. _Email) .setAttribute "project_name" pn .setAttribute "to_email" (to' ^. _Email) .setAttribute "inv_code" (renderInvCode invCode)return $ Sendgrid.EmailMessage{ from = "invitations@aftok.com", to = unpack $ to' ^. _Email, subject = unpack $ "Welcome to the "<>pn<>" Aftok!", text = render $ setAttrs template}case getStringTemplate "invitation_email" templates ofNothing -> fail "Could not find template for invitation email"Just template ->let setAttrs = setAttribute "from_email" (fromEmail ^. _Email) .setAttribute "project_name" pn .setAttribute "to_email" (toEmail ^. _Email) .setAttribute "inv_code" (renderInvCode invCode)fromAddr = Address Nothing ("invitations@aftok.com")toAddr = Address Nothing (toEmail ^. _Email)subject = "Welcome toEmail the "<>pn<>" Aftok!"body = plainTextPart . render $ setAttrs templatein pure $ SMTP.simpleMail fromAddr [toAddr] [] [] subject [body]