Learn R Programming

sendmailR (version 1.4-0)

sendmail: Send mail from within R

Description

Simplistic sendmail utility for R. Uses SMTP to submit a message to a local SMTP server.

Usage

sendmail(
  from,
  to,
  subject,
  msg,
  cc,
  bcc,
  ...,
  engine = c("internal", "curl", "debug"),
  headers = list(),
  control = list(),
  engineopts = list()
)

Arguments

from

From whom the mail message is (RFC2822 style address).

to

Recipient of the message (vector of valid RFC2822 style addresses).

subject

Subject line of message.

msg

Body text of message or a list containing mime_part objects.

cc

Carbon-copy recipients (vector of valid RFC2822 style addresses).

bcc

Blind carbon-copy recipients (vector of valid RFC2822 style addresses).

...

...

engine

One of:

  • "internal" for the internal smtp transport (default).

  • "curl" for the use of curl for transport. Enable if you need STARTTLS/SSL and/or SMTP authentication. See curl::send_mail.

  • "debug" sendmail returns a RFC2822 formatted email message without sending it.

headers

Any other headers to include.

control

List of SMTP server settings. Valid values are the possible options for sendmail_options.

engineopts

Options passed to curl if using the curl backend.

  • For authentication pass a list with username and password.

  • use_ssl defaults to "force" if unset.

  • For available options run curl::curl_options.

See Also

mime_part for a way to add attachments.

curl::send_mail for curl SMTP URL specification.

Examples

Run this code
if (FALSE) {
from <- sprintf("", Sys.info()[4])
to <- ""
subject <- "Hello from R"
body <- list("It works!", mime_part(iris))
sendmail(from, to, subject, body,
         control=list(smtpServer="ASPMX.L.GOOGLE.COM"))

sendmail(from="from@example.org",
  to=c("to1@example.org", "to2@example.org"),
  subject="SMTP auth test",
  msg=mime_part("This message was send using sendmailR and curl."),
  engine = "curl",
  engineopts = list(username = "foo", password = "bar"),
  control=list(smtpServer="smtp://smtp.gmail.com:587", verbose = TRUE)
)
}

Run the code above in your browser using DataLab