Skip to content

Instantly share code, notes, and snippets.

@MonrealRyan
Created March 14, 2018 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MonrealRyan/06ac937a6b69007dea795fb3d9c41669 to your computer and use it in GitHub Desktop.
Save MonrealRyan/06ac937a6b69007dea795fb3d9c41669 to your computer and use it in GitHub Desktop.
-- Stack.yaml
extra-deps:
- git: https://github.com/MonrealRyan/sendgrid-hs.git
commit: 13e28bd2aadf0e0ce092547292769a53f28a373e
-- Helper handler
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module Helper.Email
( sendEmailToBudzuTeamSengrid
, sendEmailContribution
) where
import Import
-- for sendgrid
import qualified Network.Sendgrid.Api as Sendgrid
import Control.Monad (when)
import qualified Data.ByteString.Lazy.UTF8 as LU
import Data.Maybe (isJust)
import Network.Mail.Mime
recipient = Address (Just "name") "email"
sendEmailToBudzuTeamSengrid :: Text -> Text -> Text -> Text -> IO ()
sendEmailToBudzuTeamSengrid name email phone message = do
let userName = unpack name
let userEmail = unpack email
let userPhone = unpack phone
let userMsg = unpack message
let content = "<p> Below are the information submitted by the user.</p> <p> Name: " ++ userName ++ "</p> <p> Email: " ++ userEmail ++ "</p> <p> Phone: " ++ userPhone ++ "</p> <p> Message : <>" ++ userMsg
-- let contentTemp = "Name: " ++ userName ++ ", Email: " ++ userEmail ++ ", Phone: " ++ userPhone ++ ", Message : " ++ userMsg
-- let contentTempV2 = "Below are the information submitted by the user \n Name: " ++ userName ++ " \n Email: " ++ userEmail ++ " \n Phone: " ++ userPhone ++ " \n Message : " ++ userMsg
let message = Sendgrid.EmailMessage {
Sendgrid.to = "contactbudzu@gmail.com"
, Sendgrid.from = "noreply@budzu.com"
, Sendgrid.subject = "User Contuct Us"
, Sendgrid.text = Nothing
, Sendgrid.html = Just content
-- "<p> Below are the information submitted by the user.</p>" ++ userName ++ "HELLO"
}
Sendgrid.sendEmail (Sendgrid.Authentication "username" "password") message
return ()
sendEmailContribution :: Text -> Text -> Text -> Text -> Maybe Text -> IO ()
sendEmailContribution username fullName email contributions videoLink = do
let userName = unpack username
let userFullName = unpack fullName
let userEmail = unpack email
let userContributions = unpack contributions
let userLink = case videoLink of
Nothing -> "no Link"
Just videoLink-> unpack $ videoLink
let content = "<p> Below are the information submitted by the user who wants to submit contributions.</p> <p> User Name: " ++ userName ++ "</p> <p> Name: " ++ userFullName ++ "</p> <p> Email: " ++ userEmail ++ "</p> <p> Contributions : " ++ userContributions ++ "</p> <p> Link : " ++ userLink
let message = Sendgrid.EmailMessage {
Sendgrid.to = "contactbudzu@gmail.com"
, Sendgrid.from = "noreply@budzu.com"
, Sendgrid.subject = "User Submit Contribution"
, Sendgrid.text = Nothing
, Sendgrid.html = Just content
-- "<p> Below are the information submitted by the user.</p>" ++ userName ++ "HELLO"
}
Sendgrid.sendEmail (Sendgrid.Authentication "username" "password") message
return ()
-- THE ERROR
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for Budzu2-0.0.0(+dev +library-only):
sengrid-haskell must match -any, but the stack configuration has no specified version
needed since Budzu2 is a build target.
Some potential ways to resolve this:
* Set 'allow-newer: true' to ignore all version constraints and build anyway.
* You may also want to try using the 'stack solver' command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment