From 0851b598a628633118ff9ad4dfa5160df6aba336 Mon Sep 17 00:00:00 2001 From: Amitai Burstein Date: Tue, 16 Jan 2024 16:18:43 +0200 Subject: [PATCH] Show example how to send a link from Mail (#1894) * Show example how to send a link from Mail * Update Guide/mail.markdown --- Guide/mail.markdown | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Guide/mail.markdown b/Guide/mail.markdown index e9fef71ad..b86344ec6 100644 --- a/Guide/mail.markdown +++ b/Guide/mail.markdown @@ -76,7 +76,7 @@ replyTo ConfirmationMail { .. } = Just Address { addessName = Just "Support", ad ### Email Content -Last we need to change the email text a little bit. The mail supports HSX so this is similar to writing an IHP view: +Lastly, we need to change the email text a little bit. The mail supports HSX, so this is similar to writing an IHP view: ```haskell html ConfirmationMail { .. } = [hsx| @@ -85,6 +85,32 @@ Last we need to change the email text a little bit. The mail supports HSX so thi |] ``` +We can also include links. It's likely that you'd have a function to return the correct link; for example, after posting a comment, you will send notifications. +Inside `Mail` we don't use `ControllerContext`, so if we have such a function we would need a different type signature. So it could work both from inside `Mail` and a `Controller`. +The reason we don't have `ControllerContext`, is because a `Mail` can be sent via IHP scripts. + +```hasekll +# Application/Helper/Controller.hs + +redirectExample :: forall context. (?context :: context, ConfigProvider context) => Text +redirectExample = urlTo LmNamesAction +``` + +Then we can use it in the `Mail`. + +```haskell + html ConfirmationMail { .. } = [hsx| + Hey {user.name},
+

+ Thanks for signing up! Please confirm your account by following this link: ... +

+ +

+ Click here to view all Posts +

+ |] +``` + ## Sending Mails From inside a controller or script, an email can be sent by using [`sendMail`](https://ihp.digitallyinduced.com/api-docs/IHP-Mail.html#v:sendMail):