Want a link in Markdown HTML to generate email, but not send it

Sorry if this is a silly question, but I'm somewhat new to R. Currently I have an R Markdown script that generates an HTML file. I would like a function that works similarly to the HTML mailto function below in order to generate an email.

<a href="mailto:email@example.com?subject=Subject&body=Text">Send Email</A>

Several problems with just using the above code:

  • My Markdown script loops and I want a link for each of those loops, with different recepients and information in the body.
  • The information in the body is relatively long (several hundred words) and contains links and tables.

I think I could use something like glue or str_glue to create a character variable with all that information and then input that into the HTML code. But this seems very difficult and would probably limit functionality like sending links or tables.

I also think there is more functionality in something like javascript to create emails, but I'm not very familiar with javascript, and not sure there's a way to get the information I have pulled in the R parts of my code (email addresses and unique information for the body of the email) into whatever email that javascript code would produce.

I do not want to automatically email anything, only to generate the email in the user's own email service (Outlook) so that they can review it and hit 'send.'

Thanks in advance.

Hi @mlasure

this should get you started

---
title: '195568'
output: html_document
date: "2024-12-10"
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Email

```{r example}
plot(1:10,1:10)
```

Really nice plot. Want more [Email text for user](mailto:email@example.com?subject=Subject&body=Text)
1 Like

Do you know of a simple way to include things like tables or very long text in the body of the email with that script?

So long text is possible

---
title: '195568'
output: html_document
date: "2024-12-10"
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Email

The following long text will be in the body of the email

```{r table, echo = FALSE}
longtext <- paste0(rep(LETTERS,30))
```

Want more [Email text for user](mailto:email@example.com?subject=Subject&body=`r longtext`)

For tables there is no easy way. Depending on where it is opened you would have to format the tables in a specific way. If the client (f.e. Outlook) supports something like HTML rendering you could provide it but i would advice against going into that direction.

1 Like

It will definitely be opened in Outlook, as this is an internal report to be used by my team.