We’ve been able to attach text and HTML content to messages with {emayili}
. But something that I’ve really been wanting to do is render markdown directly into an email.
In version 0.4.19 I’ve added the ability to directly render plain markdown into a message.
library(emayili)
The render()
method will handle plain markdown either as a character vector or from a file.
Markdown String
Let’s start with markdown in a character vector.
email <- envelope() %>%
render("[This](https://www.google.com) is a link.")
What’s the raw email document look like?
print(email, TRUE)
Date: Fri, 10 Sep 2021 03:42:47 GMT
X-Mailer: {emayili}-0.4.19
MIME-Version: 1.0
Content-type: multipart/mixed; boundary="e28a25a2a39253440353e12c623"
--e28a25a2a39253440353e12c623
Content-Type: text/html; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
<p><a href=3D"https://www.google.com">This</a> is a link.</p>
--e28a25a2a39253440353e12c623--
The markdown has been translated into HTML and inserted as a text/html
MIME element.
Markdown in a File
You’re more likely to have your markdown in a file. Suppose that the file message.md
contains the following:
[This](https://www.google.com) is a link.
- One
- Two
- Three
![](https://cran.r-project.org/Rlogo.svg)
The render()
function will identify its argument as a file path and render the contents of the file.
email <- envelope() %>%
render("message.md")
And this is what the resulting MIME message looks like:
print(email, TRUE)
Date: Fri, 10 Sep 2021 03:42:47 GMT
X-Mailer: {emayili}-0.4.19
MIME-Version: 1.0
Content-type: multipart/mixed; boundary="8301b826a4415341f24323d192f"
--8301b826a4415341f24323d192f
Content-Type: text/html; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
<p><a href=3D"https://www.google.com">This</a> is a link.</p>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
<p><img src=3D"https://cran.r-project.org/Rlogo.svg" alt=3D"" /></p>
--8301b826a4415341f24323d192f--
This new feature partially scratches a persistent itch. But I’ll only be satisfied when I can render R markdown straight into an email. Stay tuned.
Top comments (0)