Title: | Send Email Messages |
---|---|
Description: | A light, simple tool for sending emails with minimal dependencies. |
Authors: | Andrew B. Collier [aut, cre, cph], Matt Dennis [ctb], Antoine Bichat [ctb] , Daniel Fahey [ctb], Johann R. Kleinbub [ctb], Panagiotis Moulos [ctb], Swechhya Bista [ctb], Colin Fay [ctb] |
Maintainer: | Andrew B. Collier <[email protected]> |
License: | GPL-3 |
Version: | 0.9.1 |
Built: | 2024-11-21 04:25:25 UTC |
Source: | https://github.com/datawookie/emayili |
Create an address
object which represents an email address.
address( email = NA, display = NA, local = NA, domain = NA, normalise = TRUE, validate = FALSE )
address( email = NA, display = NA, local = NA, domain = NA, normalise = TRUE, validate = FALSE )
email |
Email address. |
display |
Display name. |
local |
Local part of email address. |
domain |
Domain part of email address. |
normalise |
Whether to try to normalise address to RFC-5321 requirements. |
validate |
Whether to validate the address. |
An address
object, representing an email address.
address("[email protected]") address("[email protected]", "Gerald") address("[email protected]", "Gerald Durrell") # Display name in "Last, First" format. address("[email protected]", "Durrell, Gerald") # Display name contains non-ASCII characters. address("[email protected]", "Hansjörg Müller")
address("[email protected]") address("[email protected]", "Gerald") address("[email protected]", "Gerald Durrell") # Display name in "Last, First" format. address("[email protected]", "Durrell, Gerald") # Display name contains non-ASCII characters. address("[email protected]", "Hansjörg Müller")
Add address fields to message
to(msg, ..., append = TRUE) cc(msg, ..., append = TRUE) bcc(msg, ..., append = TRUE) from(msg, addr = NULL) reply(msg, addr = NULL) return_path(msg, addr = NULL) sender(msg, addr = NULL)
to(msg, ..., append = TRUE) cc(msg, ..., append = TRUE) bcc(msg, ..., append = TRUE) from(msg, addr = NULL) reply(msg, addr = NULL) return_path(msg, addr = NULL) sender(msg, addr = NULL)
msg |
A message object. |
... |
Addresses. |
append |
Whether to append or replace addresses. |
addr |
Single address. |
A message object.
# Populating the To field. msg <- envelope() msg %>% to("[email protected], [email protected]") msg %>% to("[email protected]", "[email protected]") msg %>% to(c("[email protected]", "[email protected]")) # Populating the Cc field. msg <- envelope() msg %>% cc("[email protected], [email protected]") msg %>% cc("[email protected]", "[email protected]") msg %>% cc(c("[email protected]", "[email protected]")) # Populating the Bcc field. msg <- envelope() msg %>% bcc("[email protected], [email protected]") msg %>% bcc("[email protected]", "[email protected]") msg %>% bcc(c("[email protected]", "[email protected]")) msg <- envelope() # Populating the From field. msg %>% from("[email protected]") # Populating the Reply-To field. msg <- envelope() msg %>% reply("[email protected]") # Populating the Return-Path field. msg <- envelope() msg %>% return_path("[email protected]") # Populating the Sender field. msg <- envelope() msg %>% sender("[email protected]")
# Populating the To field. msg <- envelope() msg %>% to("[email protected], [email protected]") msg %>% to("[email protected]", "[email protected]") msg %>% to(c("[email protected]", "[email protected]")) # Populating the Cc field. msg <- envelope() msg %>% cc("[email protected], [email protected]") msg %>% cc("[email protected]", "[email protected]") msg %>% cc(c("[email protected]", "[email protected]")) # Populating the Bcc field. msg <- envelope() msg %>% bcc("[email protected], [email protected]") msg %>% bcc("[email protected]", "[email protected]") msg %>% bcc(c("[email protected]", "[email protected]")) msg <- envelope() # Populating the From field. msg %>% from("[email protected]") # Populating the Reply-To field. msg <- envelope() msg %>% reply("[email protected]") # Populating the Return-Path field. msg <- envelope() msg %>% return_path("[email protected]") # Populating the Sender field. msg <- envelope() msg %>% sender("[email protected]")
Append children to message
## S3 method for class 'envelope' after(x, child)
## S3 method for class 'envelope' after(x, child)
x |
Message object |
child |
A child to be appended |
Create an address object
as.address(addr, validate = FALSE)
as.address(addr, validate = FALSE)
addr |
An email address. |
validate |
Whether to validate the address. |
A list of address
objects.
as.address("[email protected]") as.address("Gerald <[email protected]>") as.address(c("Gerald <[email protected]>", "[email protected]", "[email protected]")) as.address("Gerald <[email protected]>, [email protected], [email protected]") as.address("Durrell, Gerald <[email protected]>")
as.address("[email protected]") as.address("Gerald <[email protected]>") as.address(c("Gerald <[email protected]>", "[email protected]", "[email protected]")) as.address("Gerald <[email protected]>, [email protected], [email protected]") as.address("Durrell, Gerald <[email protected]>")
If display name is specified as "Last, First" then the display name will be quoted.
## S3 method for class 'address' as.character(x, ...)
## S3 method for class 'address' as.character(x, ...)
x |
An |
... |
Further arguments passed to or from other methods. |
A character vector.
Accepts a message object and formats it as a MIME document.
## S3 method for class 'envelope' as.character(x, ..., details = TRUE, encode = FALSE)
## S3 method for class 'envelope' as.character(x, ..., details = TRUE, encode = FALSE)
x |
A message object. |
... |
Further arguments passed to or from other methods. |
details |
Whether or not to display full message content. |
encode |
Whether to encode headers. |
A formatted message object.
Accepts a header object and formats it as a header field.
## S3 method for class 'header' as.character(x, width = 30, ...)
## S3 method for class 'header' as.character(x, width = 30, ...)
x |
A header object. |
width |
The width of the head name field. |
... |
Further arguments passed to or from other methods. |
A formatted header field.
Convert MIME object to character vector
## S3 method for class 'MIME' as.character(x, ...)
## S3 method for class 'MIME' as.character(x, ...)
x |
MIME object |
... |
Further arguments passed to or from other methods. |
Add attachments to a message object
attachment( msg, path, name = NA, type = NA, cid = NA, disposition = "attachment" )
attachment( msg, path, name = NA, type = NA, cid = NA, disposition = "attachment" )
msg |
A message object. |
path |
Path to file. |
name |
Name to be used for attachment (defaults to base name of |
type |
MIME type or NA, which will result in a guess based on file extension. |
cid |
Content-ID or |
disposition |
How is attachment to be presented ( |
A message object.
path_mtcars <- tempfile(fileext = ".csv") path_scatter <- tempfile(fileext = ".png") path_cats <- system.file("cats.jpg", package = "emayili") write.csv(mtcars, path_mtcars) png(path_scatter) plot(1:10) dev.off() msg <- envelope() %>% attachment(path_mtcars) %>% # This attachment will have file name "cats.jpg". attachment(path_cats, name = "cats.jpg", type = "image/jpeg") %>% attachment(path_scatter, cid = "scatter") file.remove(path_scatter, path_mtcars)
path_mtcars <- tempfile(fileext = ".csv") path_scatter <- tempfile(fileext = ".png") path_cats <- system.file("cats.jpg", package = "emayili") write.csv(mtcars, path_mtcars) png(path_scatter) plot(1:10) dev.off() msg <- envelope() %>% attachment(path_mtcars) %>% # This attachment will have file name "cats.jpg". attachment(path_cats, name = "cats.jpg", type = "image/jpeg") %>% attachment(path_scatter, cid = "scatter") file.remove(path_scatter, path_mtcars)
Concatenate address objects
## S3 method for class 'address' c(...)
## S3 method for class 'address' c(...)
... |
Address objects to be concatenated. |
An address
object.
gerry <- as.address("Gerald <[email protected]>") alice <- address("[email protected]") jim <- address("[email protected]", "Jim") c(gerry, alice) c(gerry, c(alice, jim))
gerry <- as.address("Gerald <[email protected]>") alice <- address("[email protected]") jim <- address("[email protected]", "Jim") c(gerry, alice) c(gerry, c(alice, jim))
Split a compound address object
cleave(addr)
cleave(addr)
addr |
An |
A list of address
objects, each of which contains only a single
address.
cleave(as.address(c("[email protected]", "[email protected]")))
cleave(as.address(c("[email protected]", "[email protected]")))
Add or query comments of message.
comments(msg, comments = NULL)
comments(msg, comments = NULL)
msg |
A message object. |
comments |
Comments for the message. |
A message object or the comments of the message object (if comments
is NULL
).
# Create a message and set the comments. msg <- envelope() %>% comments("This is a comment") # Retrieve the comments for a message. comments(msg)
# Create a message and set the comments. msg <- envelope() %>% comments("This is a comment") # Retrieve the comments for a message. comments(msg)
Returns TRUE
wherever elements are the same (including NA
),
and FALSE
everywhere else.
compare(lhs, rhs)
compare(lhs, rhs)
lhs |
LHS of operation. |
rhs |
RHS of operation. |
A Boolean value.
Checks whether an email address conforms to the syntax rules.
compliant(addr, error = FALSE)
compliant(addr, error = FALSE)
addr |
An email address. |
error |
Whether to create an error if not compliant. |
An email address may take either of the following forms:
local@domain
or
Display Name <local@domain>
.
A Boolean.
compliant("[email protected]") compliant("alice?example.com")
compliant("[email protected]") compliant("alice?example.com")
Functions to specify the time at which a message expires or by which a reply is requested.
expires(msg, datetime = NULL, tz = "") replyby(msg, datetime = NULL, tz = "")
expires(msg, datetime = NULL, tz = "") replyby(msg, datetime = NULL, tz = "")
msg |
A message object. |
datetime |
Date and time. |
tz |
A character string specifying the time zone. |
Manipulate the Expires
and Reply-By
fields as specified in
RFC 2156.
A message object.
envelope() %>% expires("2030-01-01 13:25:00", "UTC") envelope() %>% replyby("2021-12-25 06:00:00", "GMT")
envelope() %>% expires("2030-01-01 13:25:00", "UTC") envelope() %>% replyby("2021-12-25 06:00:00", "GMT")
Extracts the display name from an email address.
display(addr)
display(addr)
addr |
An |
The display name or NA
.
gerry <- as.address("Gerald <[email protected]>") display(gerry)
gerry <- as.address("Gerald <[email protected]>") display(gerry)
Extract domain of email address
domain(addr)
domain(addr)
addr |
An |
A character vector.
domain("[email protected]")
domain("[email protected]")
Specify whether the message should be encrypted, signed or have a public key attached.
encrypt(msg, encrypt = TRUE, sign = TRUE, public_key = TRUE) signature(msg, public_key = TRUE)
encrypt(msg, encrypt = TRUE, sign = TRUE, public_key = TRUE) signature(msg, public_key = TRUE)
msg |
A message object. |
encrypt |
Whether to encrypt the message. If |
sign |
Whether to sign the message. If |
public_key |
Whether to attach a public key. If |
The signature()
function will add a digital signature to a message. It will
also optionally include a copy of the sender's public key.
The encrypt()
function will encrypt the contents of a message using the
public key(s) of the recipient(s). It can also add a digital signature to the
message (this is the default behaviour) and include a copy of the sender's
public key. Signing happens before encryption, so the digital signature
will only be accessible once the message has been decrypted. If a recipient
no longer has access to their private key or their email client is unable to
decrypt the message then they will not be able to access the message
contents.
A message object.
## Not run: msg <- envelope( from = "[email protected]", to = "[email protected]", subject = "Top Secret Message", text = "Immediate readiness. There are indications that the invasion has begun." ) # Encrypt and sign the message. msg %>% encrypt() # Only encrypt the message. msg %>% encrypt(sign = FALSE) # Only sign the message. msg %>% signature() msg %>% encrypt(encrypt = FALSE) ## End(Not run)
## Not run: msg <- envelope( from = "[email protected]", to = "[email protected]", subject = "Top Secret Message", text = "Immediate readiness. There are indications that the invasion has begun." ) # Encrypt and sign the message. msg %>% encrypt() # Only encrypt the message. msg %>% encrypt(sign = FALSE) # Only sign the message. msg %>% signature() msg %>% encrypt(encrypt = FALSE) ## End(Not run)
Create a message.
envelope( to = NULL, from = NULL, cc = NULL, bcc = NULL, reply = NULL, subject = NULL, id = NULL, importance = NULL, priority = NULL, text = NULL, html = NULL, encrypt = FALSE, sign = FALSE, public_key = FALSE )
envelope( to = NULL, from = NULL, cc = NULL, bcc = NULL, reply = NULL, subject = NULL, id = NULL, importance = NULL, priority = NULL, text = NULL, html = NULL, encrypt = FALSE, sign = FALSE, public_key = FALSE )
to |
See |
from |
See |
cc |
See |
bcc |
See |
reply |
See |
subject |
See |
id |
See |
importance |
See |
priority |
See |
text |
See |
html |
See |
encrypt |
Whether to encrypt the message. If |
sign |
Whether to sign the message. If |
public_key |
Whether to attach a public key. If |
A message object.
subject()
, from()
, to()
, cc()
, bcc()
, reply()
and
encrypt()
.
# Create an (empty) message object. # msg <- envelope() # Create a complete message object, specifying all available fields. # envelope( to = "[email protected]", from = "[email protected]", cc = "[email protected]", bcc = "[email protected]", reply = "[email protected]", importance = "high", priority = "urgent", subject = "Hiya!", text = "Hi Bob, how are you?" )
# Create an (empty) message object. # msg <- envelope() # Create a complete message object, specifying all available fields. # envelope( to = "[email protected]", from = "[email protected]", cc = "[email protected]", bcc = "[email protected]", reply = "[email protected]", importance = "high", priority = "urgent", subject = "Hiya!", text = "Hi Bob, how are you?" )
Encode email addresses in a common format
## S3 method for class 'address' format(x, quote = TRUE, encode = FALSE, ...)
## S3 method for class 'address' format(x, quote = TRUE, encode = FALSE, ...)
x |
An |
quote |
Whether to quote display name (only relevant if display name is given in "Last, First" format). |
encode |
Whether to encode headers. |
... |
Further arguments passed to or from other methods. |
A character vector.
Add an HTML body to a message object.
html( msg, content, disposition = "inline", charset = "utf-8", encoding = NA, css_files = c(), language = FALSE, interpolate = TRUE, .open = "{{", .close = "}}", .envir = NULL )
html( msg, content, disposition = "inline", charset = "utf-8", encoding = NA, css_files = c(), language = FALSE, interpolate = TRUE, .open = "{{", .close = "}}", .envir = NULL )
msg |
A message object. |
content |
A string of message content. |
disposition |
Should the content be displayed inline or as an
attachment? Valid options are |
charset |
What character set is used. Most often either |
encoding |
How content is transformed to ASCII. Options are
|
css_files |
Extra CSS files. |
language |
Language of content. If |
interpolate |
Whether or not to interpolate into input using glue. |
.open |
The opening delimiter. |
.close |
The closing delimiter. |
.envir |
Environment used for |
A message object.
# Inline HTML message. envelope() %>% html("<b>Hello!</b>") # Read HTML message from a file. htmlfile <- tempfile(fileext = ".html") cat("<p>Hello!</p>\n", file = htmlfile) envelope() %>% html(htmlfile) # You can pass a vector of character. Components will be separated by a # "\n". envelope() %>% html(c("<b>Hello</b>", "<p>World!</p>")) # You can also pass a tagList from {htmltools}. if (requireNamespace("htmltools", quietly = TRUE)) { library(htmltools) envelope() %>% html(tagList(h2("Hello"), p("World!"))) }
# Inline HTML message. envelope() %>% html("<b>Hello!</b>") # Read HTML message from a file. htmlfile <- tempfile(fileext = ".html") cat("<p>Hello!</p>\n", file = htmlfile) envelope() %>% html(htmlfile) # You can pass a vector of character. Components will be separated by a # "\n". envelope() %>% html(c("<b>Hello</b>", "<p>World!</p>")) # You can also pass a tagList from {htmltools}. if (requireNamespace("htmltools", quietly = TRUE)) { library(htmltools) envelope() %>% html(tagList(h2("Hello"), p("World!"))) }
Set message ID.
id(msg, id)
id(msg, id)
msg |
A message object. |
id |
An ID for the message. |
A message object.
# Create a message and set the ID msg <- envelope() %>% id("[email protected]") # Create a message with specified ID msg <- envelope(id="[email protected]")
# Create a message and set the ID msg <- envelope() %>% id("[email protected]") # Create a message with specified ID msg <- envelope(id="[email protected]")
Add or query keywords of message.
keywords(msg, ..., append = FALSE)
keywords(msg, ..., append = FALSE)
msg |
A message object. |
... |
Keywords. |
append |
Whether to append or replace keywords. |
A message object or the comments of the message object (if comments
is NULL
).
# Create a message and set the keywords. envelope() %>% keywords("newsletter, marketing") envelope() %>% keywords("newsletter", "marketing") envelope() %>% keywords(c("newsletter", "marketing")) # Retrieve the keywords for a message. msg <- envelope() %>% keywords("newsletter, marketing") keywords(msg)
# Create a message and set the keywords. envelope() %>% keywords("newsletter, marketing") envelope() %>% keywords("newsletter", "marketing") envelope() %>% keywords(c("newsletter", "marketing")) # Retrieve the keywords for a message. msg <- envelope() %>% keywords("newsletter, marketing") keywords(msg)
Length of address object
## S3 method for class 'address' length(x)
## S3 method for class 'address' length(x)
x |
An |
A character vector.
Extract local part of email address
local(addr)
local(addr)
addr |
An |
A character vector.
local("[email protected]")
local("[email protected]")
Create a message ID
message_id(domain = "mail.gmail.com")
message_id(domain = "mail.gmail.com")
domain |
Originating domain. |
A message ID.
message_id() message_id("example.com")
message_id() message_id("example.com")
These are parameters which occur commonly across functions for components of a MIME document.
content |
A string of message content. |
disposition |
Should the content be displayed inline or as an
attachment? Valid options are |
charset |
What character set is used. Most often either |
encoding |
How content is transformed to ASCII. Options are
|
language |
Language of content. If |
description |
Description of content. |
name |
Name used when downloading file. |
filename |
Path to a file. |
boundary |
Boundary string. |
type |
The MIME type of the content. |
children |
List of child MIME objects. |
interpolate |
Whether or not to interpolate into input using glue. |
.open |
The opening delimiter. |
.close |
The closing delimiter. |
.envir |
Environment used for |
Ensure that email address is in a standard format.
normalise(email)
normalise(email)
email |
An email address. |
Performs the following transformations:
lowercase the domain part
replace some Unicode characters with compatible equivalents. See Unicode equivalence.
An email address.
normalise("[email protected]")
normalise("[email protected]")
Extract sender and recipient(s)
parties(msg)
parties(msg)
msg |
A message object. |
A tibble.
msg <- envelope() %>% from("Gerald <[email protected]>") %>% to(c("[email protected]", "[email protected]")) %>% cc("Craig < [email protected]>") %>% bcc(" Erin <[email protected] >") parties(msg)
msg <- envelope() %>% from("Gerald <[email protected]>") %>% to(c("[email protected]", "[email protected]")) %>% cc("Craig < [email protected]>") %>% bcc(" Erin <[email protected] >") parties(msg)
Functions to influence message delivery speed and importance.
priority(msg, priority = NULL) importance(msg, importance = NULL)
priority(msg, priority = NULL) importance(msg, importance = NULL)
msg |
A message object. |
priority |
Priority level. One of |
importance |
Importance level. One of |
The priority()
function adds the Priority
header field which gives a hint
to influence transmission speed and delivery. Valid values are
"non-urgent"
, "normal"
, and "urgent"
. The non-standard X-Priority
header field is similar, for which valid values are 1
(Highest), 2
(High), 3
(Normal, the default), 4
(Low), and 5
(Lowest).
The importance()
function adds the Importance
header field, which gives a
hint to the message recipient about how important the message is. Does not
influence delivery speed.
A message object.
# How rapidly does the message need to be delivered? # envelope() %>% subject("Deliver this immediately!") %>% priority("urgent") envelope(priority = "non-urgent") %>% subject("No rush with this.") # How much attention should be paid by recipient? # envelope() %>% subject("Read this immediately!") %>% importance("high") envelope(importance = "low") %>% subject("Not important at all. Just delete.")
# How rapidly does the message need to be delivered? # envelope() %>% subject("Deliver this immediately!") %>% priority("urgent") envelope(priority = "non-urgent") %>% subject("No rush with this.") # How much attention should be paid by recipient? # envelope() %>% subject("Read this immediately!") %>% importance("high") envelope(importance = "low") %>% subject("Not important at all. Just delete.")
If display name is specifed as "Last, First" then the display name will be quoted.
## S3 method for class 'address' print(x, ...)
## S3 method for class 'address' print(x, ...)
x |
An |
... |
Further arguments passed to or from other methods. |
gerry <- as.address("[email protected]") print(gerry)
gerry <- as.address("[email protected]") print(gerry)
The message body will be printed if details
is TRUE
or if the envelope_details
option is TRUE
.
## S3 method for class 'envelope' print(x, details = NA, ...)
## S3 method for class 'envelope' print(x, details = NA, ...)
x |
A message object. |
details |
Whether or not to display full message content. |
... |
Further arguments passed to or from other methods. |
msg <- envelope() %>% text("Hello, World!") print(msg) print(msg, details = TRUE) options(envelope_details = TRUE) print(msg)
msg <- envelope() %>% text("Hello, World!") print(msg) print(msg, details = TRUE) options(envelope_details = TRUE) print(msg)
Encode to and decode from Quoted-Printable encoding.
qp_encode(x, crlf = CRLF) qp_decode(x)
qp_encode(x, crlf = CRLF) qp_decode(x)
x |
A string for encoding or decoding. |
crlf |
End-of-line characters. |
An encoded string for qp_encode()
or a decoded string for qp_decode()
.
qp_encode("Mieux vaut être seul que mal accompagné.") qp_decode("Mieux vaut =C3=AAtre seul que mal accompagn=C3=A9.")
qp_encode("Mieux vaut être seul que mal accompagné.") qp_decode("Mieux vaut =C3=AAtre seul que mal accompagn=C3=A9.")
Strips the display name off an email address (if present).
raw(addr)
raw(addr)
addr |
An |
A raw email address.
gerry <- as.address("Gerald <[email protected]>") raw(gerry)
gerry <- as.address("Gerald <[email protected]>") raw(gerry)
Request the recipient to acknowledge that they have read the message. Inserts MDN (Message Disposition Notification) header entries.
request_receipt_read(msg, addr = NULL) request_receipt_delivery(msg, addr = NULL)
request_receipt_read(msg, addr = NULL) request_receipt_delivery(msg, addr = NULL)
msg |
A message object. |
addr |
Single address (optional). If |
A message object.
Render either Plain Markdown or R Markdown directly into the body of an email.
If input
is a file then it will be interpreted as R Markdown it its
extension is either "Rmd"
or "Rmarkdown"
. Otherwise it will be
processed as Plain Markdown.
render( msg, input, params = NULL, squish = TRUE, css_files = c(), include_css = c("rmd", "bootstrap"), language = FALSE, interpolate = TRUE, .open = "{{", .close = "}}", .envir = NULL )
render( msg, input, params = NULL, squish = TRUE, css_files = c(), include_css = c("rmd", "bootstrap"), language = FALSE, interpolate = TRUE, .open = "{{", .close = "}}", .envir = NULL )
msg |
A message object. |
input |
The input Markdown file to be rendered or a character vector of Markdown text. |
params |
A list of named parameters that override custom parameters specified in the YAML front-matter. |
squish |
Whether to clean up whitespace in rendered document. |
css_files |
Extra CSS files. |
include_css |
Whether to include rendered CSS from various sources
( |
language |
Language of content. If |
interpolate |
Whether or not to interpolate into input using glue. |
.open |
The opening delimiter. |
.close |
The closing delimiter. |
.envir |
Environment used for |
A message object.
Plain Markdown is processed with commonmark::markdown_html()
.
R Markdown is processed with rmarkdown::render()
.
Regardless of what output
type is specified in the input file,
render()
will always use the "html_document"
output format.
Rending an R Markdown document can result in a lot of CSS. When all of the
CSS is included in the HTML <head>
and sent to GMail it can result in a
message which is not correctly displayed inline in the Gmail web client.
To get around this you can specify include_css = FALSE
. This will mean
that some styling will not be present in the resulting message, but that
the message content will be correctly rendered inline.
# Plain Markdown markdown <- "[This](https://www.google.com) is a link." filename <- "message.md" # Render from Markdown in character vector. msg <- envelope() %>% render(markdown) # Create a file containing Markdown cat(markdown, file = filename) # Render from Markdown in file. msg <- envelope() %>% render(filename) # Cleanup. file.remove(filename) # R Markdown filename <- "gh-doc.Rmd" # Create an Rmd document from template. rmarkdown::draft( filename, template = "github_document", package = "rmarkdown", edit = FALSE ) # Check for suitable version of Pandoc (https://pandoc.org/). # # Need to have version 2.0 or greater to support required --quiet option. # pandoc <- rmarkdown::find_pandoc() suitable_pandoc <- !is.null(pandoc$dir) && grepl("^2", pandoc$version) # Render from Rmd file. if (suitable_pandoc) { msg <- envelope() %>% render(filename, include_css = c("rmd", "bootstrap")) } # Cleanup. file.remove(filename)
# Plain Markdown markdown <- "[This](https://www.google.com) is a link." filename <- "message.md" # Render from Markdown in character vector. msg <- envelope() %>% render(markdown) # Create a file containing Markdown cat(markdown, file = filename) # Render from Markdown in file. msg <- envelope() %>% render(filename) # Cleanup. file.remove(filename) # R Markdown filename <- "gh-doc.Rmd" # Create an Rmd document from template. rmarkdown::draft( filename, template = "github_document", package = "rmarkdown", edit = FALSE ) # Check for suitable version of Pandoc (https://pandoc.org/). # # Need to have version 2.0 or greater to support required --quiet option. # pandoc <- rmarkdown::find_pandoc() suitable_pandoc <- !is.null(pandoc$dir) && grepl("^2", pandoc$version) # Render from Rmd file. if (suitable_pandoc) { msg <- envelope() %>% render(filename, include_css = c("rmd", "bootstrap")) } # Cleanup. file.remove(filename)
Add In-Reply-To and References header fields
inreplyto(msg, msgid, subject_prefix = "Re: ") references(msg, msgid, subject_prefix = "Re: ")
inreplyto(msg, msgid, subject_prefix = "Re: ") references(msg, msgid, subject_prefix = "Re: ")
msg |
A message object. |
msgid |
A message ID. This would be the contents of the |
subject_prefix |
Prefix to add to subject. If specified will be prepended
onto the |
A message object.
envelope() %>% inreplyto("<[email protected]>") # Now for German. envelope() %>% inreplyto("[email protected]", "AW: ") # And also for Danish, Norwegian and Swedish (but not Finnish!). envelope() %>% references("[email protected]", "SV: ") # Can reference multiple messages. envelope() %>% references(c( "[email protected]", "[email protected]" ))
envelope() %>% inreplyto("<[email protected]>") # Now for German. envelope() %>% inreplyto("[email protected]", "AW: ") # And also for Danish, Norwegian and Swedish (but not Finnish!). envelope() %>% references("[email protected]", "SV: ") # Can reference multiple messages. envelope() %>% references(c( "[email protected]", "[email protected]" ))
Manipulate the Sensitivity
field as specified in RFC 2156.
sensitivity(msg, sensitivity = NULL)
sensitivity(msg, sensitivity = NULL)
msg |
A message object. |
sensitivity |
Sensitivity level. One of |
A message object.
# Not sensitive. envelope() %>% subject("Your daily dose of spam") # Sensitive personal message. envelope() %>% subject("The results from your test") %>% sensitivity("personal") # Sensitive private message. envelope() %>% subject("Your OTP (don't show this to anybody!") %>% sensitivity("private") # Sensitive business message. envelope() %>% subject("Top Secret Strategy Document") %>% sensitivity("company-confidential")
# Not sensitive. envelope() %>% subject("Your daily dose of spam") # Sensitive personal message. envelope() %>% subject("The results from your test") %>% sensitivity("personal") # Sensitive private message. envelope() %>% subject("Your OTP (don't show this to anybody!") %>% sensitivity("private") # Sensitive business message. envelope() %>% subject("Top Secret Strategy Document") %>% sensitivity("company-confidential")
Create an object which can be used to send messages to an SMTP server.
server( host, port = 25, username = NULL, password = NULL, insecure = FALSE, reuse = TRUE, helo = NA, protocol = NA, use_ssl = NA, test = FALSE, pause_base = 1, max_times = 5, ... ) gmail(username, password, ...) sendgrid(password, ...) mailgun(username, password, ...) sendinblue(username, password, ...) mailersend(username, password, ...) mailfence(username, password, ...) zeptomail(password, ...) smtpbucket(...) mailtrap(username, password, sandbox = FALSE, bulk = FALSE, ...)
server( host, port = 25, username = NULL, password = NULL, insecure = FALSE, reuse = TRUE, helo = NA, protocol = NA, use_ssl = NA, test = FALSE, pause_base = 1, max_times = 5, ... ) gmail(username, password, ...) sendgrid(password, ...) mailgun(username, password, ...) sendinblue(username, password, ...) mailersend(username, password, ...) mailfence(username, password, ...) zeptomail(password, ...) smtpbucket(...) mailtrap(username, password, sandbox = FALSE, bulk = FALSE, ...)
host |
DNS name or IP address of the SMTP server. |
port |
Port that the SMTP server is listening on. |
username |
Username for SMTP server. |
password |
Password for SMTP server or API key. |
insecure |
Whether to ignore SSL issues. |
reuse |
Whether the connection to the SMTP server should be left open for reuse. |
helo |
The HELO domain name of the sending host. If left as |
protocol |
Which protocol (SMTP or SMTPS) to use for communicating with the server. Default will choose appropriate protocol based on port. |
use_ssl |
Whether to use SSL. If not specified then SSL will be used if the port is 465 or 587. This enables SSL on non-standard ports. |
test |
Test login to server. |
pause_base |
Base delay (in seconds) for exponential backoff. See rate_backoff. |
max_times |
Maximum number of times to retry. |
... |
Additional curl options. See |
sandbox |
Use email sandbox to test server. |
bulk |
Send bulk mail to multiple recipients. |
These functions return a function that can then be called with a message object. This function mediates the interaction with the Simple Mail Transfer Protocol (SMTP) server.
SMTP is a plain text protocol, which means that it is not secure. The secure variant, SMTPS, comes in two flavours: TLS and StartTLS. With TLS (also called Implicit TLS) the connection with the server is initiated using an Secure Socket Layer (SSL) or Transport Layer Security (TLS) certificate. Such a connection is secure from the start. By contract, a StartTLS connection is initiated in plain text and then upgraded to TLS if possible. By convention TLS operates on port 465 and StartTLS on port 587.
The specifications of an SMTP server are given in an SMTP URL, which takes one of the following forms:
mail.example.com
— hostname only
mail.example.com:587
— hostname and port
smtp://mail.example.com
— SMTP URL (default port)
smtps://mail.example.com
— SMTPS URL (default port)
smtp://mail.example.com:25
— SMTP URL (explicit port)
smtps://mail.example.com:587
— SMTPS URL (explicit port)
A function which is used to send messages to the server.
If you're having trouble authenticating with Gmail then you should try the following:
enable 2-factor authentication and
create an app password.
Then use the app password rather than your usual account password.
To use SendGrid you'll need to first create an API key. # nolint Then use the API key as the password.
SendGrid will accept messages on ports 25, 587 and 2525 (using SMTP) as well as 465 (using SMTPS).
To use Mailgun you'll need to first register a sender domain. This will then be assigned a username and password.
Mailgun will accept messages on ports 25 and 587 (using SMTP) as well as 465 (using SMTPS).
To use Sendinblue you'll need to first create an account. You'll find your SMTP username and password in the SMTP & API section of your account settings.
To use MailerSend you'll need to first create an account. You'll find your SMTP username and password under Domains. See How to send emails via SMTP with MailerSend.
Although this is not likely to be a problem in practice, MailerSend insists that all messages have at minimum a valid subject and either text or HTML content.
To use Mailfence you'll need to create a premium account.
Zeptomail is an email sending service provided by Zoho Corporation. It is designed primarily for transactional email delivery, which includes emails like password resets, order confirmations, notifications, and other automated, non-marketing communications that websites and applications need to send to their users.
SMTP Bucket is a fake SMTP server that captures all the messages it receives and makes them available through a website or REST API.
SMTP Bucket is a fake SMTP server that captures all the messages it receives and makes them available through a website or REST API.
# Set parameters for SMTP server (with username and password). smtp <- server( host = "smtp.gmail.com", port = 587, username = "[email protected]", password = "bd40ef6d4a9413de9c1318a65cbae5d7" ) # Set parameters for a (fake) testing SMTP server. # # More information about this service can be found at https://www.smtpbucket.com/. # smtp <- server( host = "mail.smtpbucket.com", port = 8025 ) # Create a message msg <- envelope() %>% from("[email protected]") %>% to("[email protected]") # Send message (verbose output from interactions with server) ## Not run: smtp(msg, verbose = TRUE) ## End(Not run) # To confirm that the message was sent, go to https://www.smtpbucket.com/ then: # # - fill in "[email protected]" for the Sender field and # - fill in "[email protected]" for the Recipient field then # - press the Search button. # With explicit HELO domain. # smtp <- server( host = "mail.example.com", helo = "client.example.com" ) # Set parameters for Gmail SMTP server. The host and port are implicit. smtp <- gmail( username = "[email protected]", password = "bd40ef6d4a9413de9c1318a65cbae5d7" ) # Set API key for SendGrid SMTP server. smtp <- sendgrid( password = "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" ) # Set username and password for Mailgun SMTP server. smtp <- mailgun( username = "[email protected]", password = "44d072e7g2b5f3bf23b2b642da0fe3a7-2ac825a1-a5be680a" ) # Set username and password for Sendinblue SMTP server. smtp <- sendinblue( username = "[email protected]", password = "xsmtpsib-c75cf91323adc53a1747c005447cbc9a893c35888635bb7bef1a624bf773da33" ) # Set username and password for MailerSend SMTP server. smtp <- mailersend( username = "[email protected]", password = "e5ATWLlTnWWDaKeE" ) # Set username and password for Mailfence SMTP server. smtp <- mailfence( username = "bob", password = "F!Uosd6xbhSjd%63" ) # Set password for ZeptoMail SMTP server. # nolint start smtp <- zeptomail("yA6KbHsL4l2mmI8Ns0/fs9iSTj8yG0dYBgfIG0j6Fsv4P2uV32xh8ciEYNYlRkgCC7wRfkgWA==") # nolint end # SMTP Bucket server. smtp <- smtpbucket() # SMTP Bucket server. smtp <- smtpbucket()
# Set parameters for SMTP server (with username and password). smtp <- server( host = "smtp.gmail.com", port = 587, username = "[email protected]", password = "bd40ef6d4a9413de9c1318a65cbae5d7" ) # Set parameters for a (fake) testing SMTP server. # # More information about this service can be found at https://www.smtpbucket.com/. # smtp <- server( host = "mail.smtpbucket.com", port = 8025 ) # Create a message msg <- envelope() %>% from("[email protected]") %>% to("[email protected]") # Send message (verbose output from interactions with server) ## Not run: smtp(msg, verbose = TRUE) ## End(Not run) # To confirm that the message was sent, go to https://www.smtpbucket.com/ then: # # - fill in "[email protected]" for the Sender field and # - fill in "[email protected]" for the Recipient field then # - press the Search button. # With explicit HELO domain. # smtp <- server( host = "mail.example.com", helo = "client.example.com" ) # Set parameters for Gmail SMTP server. The host and port are implicit. smtp <- gmail( username = "[email protected]", password = "bd40ef6d4a9413de9c1318a65cbae5d7" ) # Set API key for SendGrid SMTP server. smtp <- sendgrid( password = "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" ) # Set username and password for Mailgun SMTP server. smtp <- mailgun( username = "[email protected]", password = "44d072e7g2b5f3bf23b2b642da0fe3a7-2ac825a1-a5be680a" ) # Set username and password for Sendinblue SMTP server. smtp <- sendinblue( username = "[email protected]", password = "xsmtpsib-c75cf91323adc53a1747c005447cbc9a893c35888635bb7bef1a624bf773da33" ) # Set username and password for MailerSend SMTP server. smtp <- mailersend( username = "[email protected]", password = "e5ATWLlTnWWDaKeE" ) # Set username and password for Mailfence SMTP server. smtp <- mailfence( username = "bob", password = "F!Uosd6xbhSjd%63" ) # Set password for ZeptoMail SMTP server. # nolint start smtp <- zeptomail("yA6KbHsL4l2mmI8Ns0/fs9iSTj8yG0dYBgfIG0j6Fsv4P2uV32xh8ciEYNYlRkgCC7wRfkgWA==") # nolint end # SMTP Bucket server. smtp <- smtpbucket() # SMTP Bucket server. smtp <- smtpbucket()
Add or query subject of message.
subject( msg, subject = NULL, prefix = NA, suffix = NA, interpolate = TRUE, .open = "{{", .close = "}}", .envir = NULL )
subject( msg, subject = NULL, prefix = NA, suffix = NA, interpolate = TRUE, .open = "{{", .close = "}}", .envir = NULL )
msg |
A message object. |
subject |
A subject for the message. |
prefix |
A subject prefix. |
suffix |
A subject suffix. |
interpolate |
Whether or not to interpolate into input using glue. |
.open |
The opening delimiter. |
.close |
The closing delimiter. |
.envir |
Environment used for |
The prefix
and suffix
can be used to add extra
subject
abbreviations.
A message object or the subject of the message object (if subject
is NULL
).
# Create a message and set the subject msg <- envelope() %>% subject("Updated report") # Retrieve the subject for a message subject(msg)
# Create a message and set the subject msg <- envelope() %>% subject("Updated report") # Retrieve the subject for a message subject(msg)
Variables given as named arguments will override any variables in the environment with the same name.
template(msg, .name, ..., .envir = parent.frame())
template(msg, .name, ..., .envir = parent.frame())
msg |
A message object. |
.name |
A template name. This can be provided as either: (i) the name of a template that's baked into the package, (ii) a relative path or (iii) an absolute path. The paths must be for the directory containing the template files, not the files themselves. |
... |
Variables for substitution. |
.envir |
Environment for substitution. |
Will probably not get variables from environment if used as part of a
pipeline. In this case might need to use the %|>%
(nested pipe)
operator.
A message object.
# Use a builtin template. envelope() %>% template( "newsletter", title = "A Sample Newsletter", articles = list( list( "title" = "Article (with date)", "content" = as.list("Vivamus, justo quisque, sed."), "date" = "1 January 2022" ), list( "title" = "Another Article (without date)", "content" = as.list("Quam lorem sed metus egestas.") ) ) ) # Use a custom local template. ## Not run: envelope() %>% template("./templates/custom-template") ## End(Not run)
# Use a builtin template. envelope() %>% template( "newsletter", title = "A Sample Newsletter", articles = list( list( "title" = "Article (with date)", "content" = as.list("Vivamus, justo quisque, sed."), "date" = "1 January 2022" ), list( "title" = "Another Article (without date)", "content" = as.list("Quam lorem sed metus egestas.") ) ) ) # Use a custom local template. ## Not run: envelope() %>% template("./templates/custom-template") ## End(Not run)
Add text/plain
content to a message.
text( msg, content, disposition = "inline", charset = "utf-8", encoding = "7bit", language = FALSE, interpolate = TRUE, .open = "{{", .close = "}}", .envir = NULL )
text( msg, content, disposition = "inline", charset = "utf-8", encoding = "7bit", language = FALSE, interpolate = TRUE, .open = "{{", .close = "}}", .envir = NULL )
msg |
A message object. |
content |
A string of message content. |
disposition |
Should the content be displayed inline or as an
attachment? Valid options are |
charset |
What character set is used. Most often either |
encoding |
How content is transformed to ASCII. Options are
|
language |
Language of content. If |
interpolate |
Whether or not to interpolate into input using glue. |
.open |
The opening delimiter. |
.close |
The closing delimiter. |
.envir |
Environment used for |
The text/plain
format is
described in RFC 2646.
Uses glue::glue()
to evaluate expressions enclosed in brackets as R code.
A message object.
msg <- envelope() %>% text("Hello!") # Using {glue} interpolation. # name <- "Alice" msg <- envelope() %>% text("Hello {name}.") print(msg, details = TRUE) # Disable {glue} interpolation. # msg <- envelope() %>% text("This is a set: {1, 2, 3}.", interpolate = FALSE)
msg <- envelope() %>% text("Hello!") # Using {glue} interpolation. # name <- "Alice" msg <- envelope() %>% text("Hello {name}.") print(msg, details = TRUE) # Disable {glue} interpolation. # msg <- envelope() %>% text("This is a set: {1, 2, 3}.", interpolate = FALSE)
Validate email address
validate(addr, deliverability = TRUE)
validate(addr, deliverability = TRUE)
addr |
An email address. |
deliverability |
Whether to check for deliverability (valid domain). |
A logical
indicating whether or not the address is valid.
# A valid address. validate("[email protected]") # An invalid address. validate("[email protected]")
# A valid address. validate("[email protected]") # An invalid address. validate("[email protected]")