Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit cb5e2a070409c02ccbdd32606aadda8651f41a10 @qzchenwl committed Nov 5, 2011
Showing with 67 additions and 0 deletions.
  1. +31 −0 sendmail-via-http.cabal
  2. +36 −0 src/Main.hs
@@ -0,0 +1,31 @@
+Name: sendmail-via-http
+Version: 0.1
+Synopsis: Project Synopsis Here
+Description: Project Description Here
+License: AllRightsReserved
+Author: Author
+Maintainer: maintainer@example.com
+Stability: Experimental
+Category: Web
+Build-type: Simple
+Cabal-version: >=1.2
+
+Executable sendmail-via-http
+ hs-source-dirs: src
+ main-is: Main.hs
+
+ Build-depends:
+ base >= 4 && < 5,
+ bytestring >= 0.9.1 && < 0.10,
+ MonadCatchIO-transformers >= 0.2.1 && < 0.3,
+ mtl >= 2 && < 3,
+ snap-core == 0.6.*,
+ snap-server == 0.6.*,
+ cgi == 3001.*,
+ shqq == 0.1.*
+
+ if impl(ghc >= 6.12.0)
+ ghc-options: -threaded -Wall -fwarn-tabs -funbox-strict-fields -O2
+ -fno-warn-unused-do-bind
+ else
+ ghc-options: -threaded -Wall -fwarn-tabs -funbox-strict-fields -O2
@@ -0,0 +1,36 @@
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE QuasiQuotes #-}
+
+module Main where
+
+import Snap.Core
+import Snap.Http.Server
+import Snap.Util.FileServe
+import System.ShQQ
+import Data.Int
+import Network.CGI (liftIO)
+import Data.Maybe (fromJust)
+import qualified Data.ByteString.Lazy.Char8 as L (unpack)
+import qualified Data.ByteString.Char8 as S (unpack)
+
+main :: IO ()
+main = quickHttpServe $
+ route [ ("mailto/:receiver/:subject", sendMailHandler)
+ , ("static" , fileServer)
+ ]
+ where
+ fileServer = serveDirectory "/home/admin/BizCardCallCount"
+
+sendMailHandler :: Snap()
+sendMailHandler = do
+ receiver <- getParam "receiver"
+ subject <- getParam "subject"
+ body <- readRequestBody (maxBound :: Int64)
+ liftIO $ sendMail (S.unpack $ fromJust receiver)
+ (S.unpack $ fromJust subject)
+ (L.unpack body)
+ writeBS "mail sent\n"
+
+sendMail :: String -> String -> String -> IO String
+sendMail receiver subject body =
+ [sh| echo $body | mail -s $subject $receiver |]

0 comments on commit cb5e2a0

Please sign in to comment.