self-hosted listenbrainz and last.fm proxy
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253module Mail (Mail, isConfigured, sendMail) where
import Prelude
import Config (SmtpConfig)import Data.Either (Either(..))import Data.Function.Uncurried (Fn3, runFn3)import Data.Maybe (Maybe(..), isJust)import Data.Nullable (Nullable, toMaybe, toNullable)import Effect (Effect)import Effect.Aff (Aff, makeAff, nonCanceler)import Effect.Exception (Error)
type SmtpConfigJs = { host :: Nullable String , port :: Int , user :: Nullable String , pass :: Nullable String , from :: Nullable String }
-- | A plaintext email to be delivered through SMTP.type Mail = { to :: String , subject :: String , text :: String }
toJs :: SmtpConfig -> SmtpConfigJstoJs cfg = { host: toNullable cfg.host , port: cfg.port , user: toNullable cfg.user , pass: toNullable cfg.pass , from: toNullable cfg.from }
-- | True when SMTP is configured (host present).isConfigured :: SmtpConfig -> BooleanisConfigured cfg = isJust cfg.host
foreign import sendMailImpl :: Fn3 SmtpConfigJs Mail (Nullable Error -> Effect Unit) (Effect Unit)
-- | Sends one plaintext email over SMTP (STARTTLS). Wrap callers in `try`.sendMail :: SmtpConfig -> Mail -> Aff UnitsendMail cfg mail = makeAff \cb -> do runFn3 sendMailImpl (toJs cfg) mail \err -> case toMaybe err of Just e -> cb (Left e) Nothing -> cb (Right unit) pure nonCanceler