Learn R Programming

⚠️There's a newer version (0.9.3) of this package.Take me there.

emayili

emayili is a package for sending emails from R. The design goals are:

  • works on all manner of SMTP servers and
  • has minimal dependencies (or dependencies which are easily satisfied).

The package name is an adaption of the Zulu word for email, imeyili.

Installation

Get the stable version from CRAN.

install.packages("emayili")

Or grab it directly from GitHub.

# Install from the master branch.
remotes::install_github("datawookie/emayili")
# Install from the development branch.
remotes::install_github("datawookie/emayili", ref = "dev")

Usage

First create a message object.

library(emayili)
library(magrittr)

email <- envelope()

Creating a Message

The message has class envelope.

class(email)
[1] "envelope"

Add addresses for the sender and recipient.

email <- email %>%
  from("alice@yahoo.com") %>%
  to("bob@google.com") %>%
  cc("craig@google.com")

There are also bcc() and reply() functions for setting the Bcc and Reply-To fields.

Add a subject.

email <- email %>% subject("This is a plain text message!")

Add a text body. You can use html() to add an HTML body.

email <- email %>% text("Hello!")

Add an attachment.

email <- email %>% attachment("image.jpg")

You can also create the message in a single command:

email <- envelope(
  to = "bob@google.com",
  from = "alice@yahoo.com",
  subject = "This is a plain text message!",
  text = "Hello!"
)

Simply printing a message displays the header information.

email
Date:         Fri, 02 Oct 2020 14:17:38 GMT
From:         alice@yahoo.com
To:           bob@google.com
Cc:           craig@google.com
Subject:      This is a plain text message!
X-Mailer:     {emayili}-0.4.3

You can identify emails which have been sent using {emayili} by the presence of an X-Mailer header which includes both the package name and version.

If you want to see the complete MIME object, just convert to a string.

as.character(email)

Sending a Message

Create a SMTP server object and send the message.

smtp <- server(host = "smtp.gmail.com",
               port = 465,
               username = "bob@gmail.com",
               password = "bd40ef6d4a9413de9c1318a65cbae5d7")
smtp(email, verbose = TRUE)

To see the guts of the message as passed to the SMTP server:

print(email, details = TRUE)

Using STARTTLS

If you’re trying to send email with a host that uses the STARTTLS security protocol (like Google Mail, Yahoo! or AOL), then it will most probably be blocked due to insufficient security. In order to circumvent this, you can grant access to less secure apps. See the links below for specifics:

Similar Packages

There is a selection of other R packages which also send emails:

Copy Link

Version

Install

install.packages('emayili')

Monthly Downloads

2,618

Version

0.4.4

License

GPL-3

Maintainer

Andrew Collier

Last Published

October 2nd, 2020

Functions in emayili (0.4.4)

as.character.envelope

Create formatted message.
text

Add a text body to a message.
header

Create formatted header.
to

Add To field to message
print.envelope

Print a message object
qp_decode

Decode a quoted-printable string.
qp_encode

Encode a string to quoted-printable.
server

Create a SMTP server object.
reply

Add Reply-To field to message
subject

Add or query subject of message.
bcc

Add Bcc field to message
mime

Create a MIME (Multipurpose Internet Mail Extensions) object.
html

Add an HTML body to a message object.
envelope

Create a message.
format.mime

Format the header of a MIME object.
cc

Add Cc field to message
from

Add From field to message
attachment

Add attachments to a message object