Title: | 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'. |
Authors: | Andrie de Vries [aut, cre] |
Maintainer: | Andrie de Vries <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.5 |
Built: | 2024-10-27 04:19:57 UTC |
Source: | https://github.com/andrie/mailmerge |
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.
mail_merge( data, message, to_col = "email", send = c("preview", "draft", "immediately"), confirm = FALSE, sleep_preview = 1, sleep_send = 0.1 )
mail_merge( data, message, to_col = "email", send = c("preview", "draft", "immediately"), confirm = FALSE, sleep_preview = 1, sleep_send = 0.1 )
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 |
Returns a list for every message, consisting of:
msg
: The message in mime
format
id
: The gmailr
response id
type
: preview, draft or sent
success
: TRUE if the message was sent successfully
## ---- input-data -------------------------------------------------------- dat <- data.frame( email = c("[email protected]", "[email protected]"), 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() }
## ---- input-data -------------------------------------------------------- dat <- data.frame( email = c("[email protected]", "[email protected]"), 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() }
Read a markdown file from google drive
mm_read_googledoc(id)
mm_read_googledoc(id)
id |
Unique Google Drive identifier, passed to googledrive::drive_download |
the imported document
A list of character strings, containing the content of the google doc
You can use this to construct the message
argument of mail_merge()
.
mm_read_message(txt)
mm_read_message(txt)
txt |
A file in markdown format |
A list with components yaml
and body
Other parsing functions:
mm_read_message_googledoc()
You can use this to construct the message
argument of mail_merge()
.
mm_read_message_googledoc(id)
mm_read_message_googledoc(id)
id |
Unique Google Drive identifier, passed to googledrive::drive_download |
A list of character strings
Other parsing functions:
mm_read_message()
preview_mailmerge(x)
preview_mailmerge(x)
x |
mailmerge_preview object, from mail_merge |
A 'shiny' gadget, see also shiny::runGadget
## ---- input-data -------------------------------------------------------- dat <- data.frame( email = c("[email protected]", "[email protected]"), 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() }
## ---- input-data -------------------------------------------------------- dat <- data.frame( email = c("[email protected]", "[email protected]"), 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() }