Title: | Mail Merge Using R Markdown Documents and 'gmailr' |
Version: | 0.2.5 |
Description: | Perform a mail merge (mass email) using the message defined in markdown, the recipients in a 'csv' file, and gmail as the mailing engine. With this package you can parse markdown documents as the body of email, and the 'yaml' header to specify the subject line of the email. Any '{}' braces in the email will be encoded with 'glue::glue()'. You can preview the email in the RStudio viewer pane, and send (draft) email using 'gmailr'. |
License: | MIT + file LICENSE |
URL: | https://andrie.github.io/mailmerge/, https://github.com/andrie/mailmerge |
BugReports: | https://github.com/andrie/mailmerge/issues |
Depends: | R (≥ 3.3) |
Imports: | commonmark, gmailr, rstudioapi, googledrive, rmarkdown, glue, magrittr, purrr, utils, fs, lifecycle, shiny, miniUI |
Suggests: | spelling, withr, covr, knitr, testthat (≥ 2.1.0), here, mockery, readr |
VignetteBuilder: | knitr |
RdMacros: | lifecycle |
Encoding: | UTF-8 |
RoxygenNote: | 7.2.1 |
Language: | en-US |
Config/testthat/edition: | 3 |
NeedsCompilation: | no |
Packaged: | 2022-08-14 20:16:00 UTC; apdev |
Author: | Andrie de Vries [aut, cre] |
Maintainer: | Andrie de Vries <apdevries@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2022-08-14 20:30:02 UTC |
mailmerge: Mail Merge Using R Markdown Documents and 'gmailr'
Description
Perform a mail merge (mass email) using the message defined in markdown, the recipients in a 'csv' file, and gmail as the mailing engine. With this package you can parse markdown documents as the body of email, and the 'yaml' header to specify the subject line of the email. Any '' braces in the email will be encoded with 'glue::glue()'. You can preview the email in the RStudio viewer pane, and send (draft) email using 'gmailr'.
Details
The main function in this package is mail_merge()
Author(s)
Maintainer: Andrie de Vries apdevries@gmail.com
See Also
Useful links:
Report bugs at https://github.com/andrie/mailmerge/issues
Pipe operator
Description
See magrittr::%>%
for details.
Usage
lhs %>% rhs
Arguments
lhs |
A value or the magrittr placeholder. |
rhs |
A function call using the magrittr semantics. |
Value
The result of calling rhs(lhs)
.
Display email message in RStudio viewer pane.
Description
Only opens the viewer pane if interactive and RStudio is the IDE, otherwise returns the input invisibly.
Usage
in_viewer(x)
Arguments
x |
message |
Value
An rstudioapi::viewer object. Called for the side effect of opening the viewer pane and displays message
Merges data into an email and send.
Description
Merges columns from a data frame into a markdown document using the
glue::glue_data()
function. The markdown can contain a yaml header for
subject and cc line.
Note that only 'gmail' is supported at the moment, via gmailr::gm_send_message.
Before using mail_merge()
, you must be authenticated to the gmail service.
Use gmailr::gm_auth()
to authenticate prior to starting the mail merge.
Usage
mail_merge(
data,
message,
to_col = "email",
send = c("preview", "draft", "immediately"),
confirm = FALSE,
sleep_preview = 1,
sleep_send = 0.1
)
Arguments
data |
A data frame or |
message |
A list with components |
to_col |
The name of the column in |
send |
A character string, one of:
|
confirm |
If |
sleep_preview |
If |
sleep_send |
If |
Value
Returns a list for every message, consisting of:
-
msg
: The message inmime
format -
id
: Thegmailr
response id -
type
: preview, draft or sent -
success
: TRUE if the message was sent successfully
See Also
Examples
## ---- input-data --------------------------------------------------------
dat <- data.frame(
email = c("friend@example.com", "foe@example.com"),
first_name = c("friend", "foe"),
thing = c("something good", "something bad"),
stringsAsFactors = FALSE
)
## ---- markdown-message --------------------------------------------------
msg <- '
---
subject: "**Hello, {first_name}**"
---
Hi, **{first_name}**
I am writing to tell you about **{thing}**.
{if (first_name == "friend") "Regards" else ""}
Me
'
## ---- mail-merge --------------------------------------------------------
dat %>%
mail_merge(msg)
if (interactive()) {
dat %>%
mail_merge(msg) %>%
print()
}
## ---- display shiny gadget ----------------------------------------------
if (interactive()) {
dat %>%
mail_merge(msg) %>%
preview_mailmerge()
}
Preview message in viewer pane.
Description
Preview message in viewer pane.
Usage
mm_preview_mail(to, subject = "", body, cc = "")
Arguments
to |
The email |
subject |
The email subject |
body |
The email message, in markdown format |
cc |
The email |
Value
HTML text
Read a markdown file from google drive
Description
Read a markdown file from google drive
Usage
mm_read_googledoc(id)
Arguments
id |
Unique Google Drive identifier, passed to googledrive::drive_download |
Value
the imported document
A list of character strings, containing the content of the google doc
Parse a markdown document into yaml and body components.
Description
You can use this to construct the message
argument of mail_merge()
.
Usage
mm_read_message(txt)
Arguments
txt |
A file in markdown format |
Value
A list with components yaml
and body
See Also
Other parsing functions:
mm_read_message_googledoc()
Parse the email template inside a markdown document on google drive.
Description
You can use this to construct the message
argument of mail_merge()
.
Usage
mm_read_message_googledoc(id)
Arguments
id |
Unique Google Drive identifier, passed to googledrive::drive_download |
Value
A list of character strings
See Also
Other parsing functions:
mm_read_message()
Send draft email.
Description
Send draft email.
Usage
mm_send_draft(to, body, subject, cc = NULL, draft = TRUE)
Arguments
to |
The email |
body |
The email message, in markdown format |
subject |
The email subject |
cc |
The email |
draft |
if |
Value
A draft email message
Send email.
Description
Send email.
Usage
mm_send_mail(
to,
body,
subject,
cc = NULL,
draft = FALSE,
test = Sys.getenv("mailmerge_test", FALSE)
)
Arguments
to |
The email |
body |
The email message, in markdown format |
subject |
The email subject |
cc |
The email |
draft |
if |
test |
If TRUE, doesn't send email but simply returns |
Value
An email message
Preview mailmerge as shiny gadget in RStudio preview pane.
Description
Usage
preview_mailmerge(x)
Arguments
x |
mailmerge_preview object, from mail_merge |
Value
A 'shiny' gadget, see also shiny::runGadget
See Also
Examples
## ---- input-data --------------------------------------------------------
dat <- data.frame(
email = c("friend@example.com", "foe@example.com"),
first_name = c("friend", "foe"),
thing = c("something good", "something bad"),
stringsAsFactors = FALSE
)
## ---- markdown-message --------------------------------------------------
msg <- '
---
subject: "**Hello, {first_name}**"
---
Hi, **{first_name}**
I am writing to tell you about **{thing}**.
{if (first_name == "friend") "Regards" else ""}
Me
'
## ---- display shiny gadget ----------------------------------------------
if (interactive()) {
dat %>%
mail_merge(msg) %>%
preview_mailmerge()
}
Wait for interactive response to yes/no challenge question.
Description
Copied from devtools:::yesno
Usage
yesno(...)
Arguments
... |
Arguments to paste together to form challenge question. |
Value
logical value