mail_merge {mailmerge} | R Documentation |
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()
}