Paste server written in Haskell. Fork of Hpaste, fully freedom and privacy respecting and generally improved. At the time of writing there's an instance at <http://paste.rel4tion.org>.

[[ 🗃 ^aoqmo toothpaste ]] :: [📥 Inbox] [📤 Outbox] [🐤 Followers] [🤝 Collaborators] [🛠 Commits]

Clone

HTTPS: git clone https://vervis.peers.community/repos/aoqmo

SSH: git clone USERNAME@vervis.peers.community:aoqmo

Branches

Tags

master :: src / Network /

Email.hs

module Network.SendEmail where

-- | An email to be sent via SMTP.
data Email =
  Email { emailSMTPHost :: String
        , emailEHLO :: String
        , emailFromName :: String
        , emailToName :: String
        , emailFromEmail :: String
        , emailToEmail :: String
        , emailSubject :: String
        , emailBody :: String
        }

-- | Send an SMTP email.
sendEmail :: (MonadIO m) => Email -> m ()
sendEmail Email{..} =
  io $ do
  addr <- lookupIP emailSMTPHost
  case addr of
    Just ip -> sendSimpleMessages putStrLn ip emailEHLO [msg]
    Nothing -> error "Unable to lookup the SMTP IP."
  where msg = SimpleMessage {
                from    = [NameAddr (Just emailFromName) emailFromEmail]
              , to      = [NameAddr (Just emailToName) emailToEmail]
              , subject = emailSubject
              , body    = emailBody
              }
        -- | Look up the IP address for the SMTP server.
        lookupIP :: MonadIO m => String -> m (Maybe String)
        lookupIP domain = io $ do
          let hints = defaultHints { addrFlags = [AI_ADDRCONFIG, AI_CANONNAME] }
          addrs <- getAddrInfo (Just hints) (Just domain) (Just "smtp")
          return $ listToMaybe $ map (takeWhile (/=':') . show . addrAddress) addrs
[See repo JSON]