Skip to content

Commit

Permalink
Show example how to send a link from Mail (#1894)
Browse files Browse the repository at this point in the history
* Show example how to send a link from Mail

* Update Guide/mail.markdown
  • Loading branch information
amitaibu authored Jan 16, 2024
1 parent 0285256 commit 0851b59
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion Guide/mail.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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}, <br/>
<p>
Thanks for signing up! Please confirm your account by following this link: ...
</p>

<p>
<a href={redirectExample}>Click here to view all Posts</a>
</p>
|]
```

## 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):
Expand Down

0 comments on commit 0851b59

Please sign in to comment.