Package 'mailR'

Title: A Utility to Send Emails from R
Description: Interface to Apache Commons Email to send emails from R.
Authors: Rahul Premraj
Maintainer: Rahul Premraj <[email protected]>
License: GPL-3
Version: 0.8
Built: 2024-11-27 06:34:40 UTC
Source: CRAN

Help Index


Send emails from R

Description

Send emails from R

Usage

send.mail(
  from,
  to,
  subject = "",
  body = "",
  encoding = "iso-8859-1",
  html = FALSE,
  inline = FALSE,
  smtp = list(),
  authenticate = FALSE,
  timeout = 60000,
  send = TRUE,
  attach.files = NULL,
  debug = FALSE,
  ...
)

Arguments

from

A valid email address of the sender.

to

A character vector of recipient valid email addresses.

subject

Subject of the email.

body

Body of the email as text. If the parameter body refers to an existing file location, the text of the file is parsed as body of the email.

encoding

Character encoding to use for the email. Supported encodings include iso-8859-1 (default), utf-8, us-ascii, and koi8-r.

html

A boolean indicating whether the body of the email should be parsed as HTML.

inline

A boolean indicating whether images in the HTML file should be embedded inline.

smtp

A list of configuration parameters to establish and authorize a connection with the SMTP server. See details for the various parameters.

authenticate

A boolean variable to indicate whether authorization is required to connect to the SMTP server. If set to true, see details on parameters required in smtp parameter.

timeout

An integer with the number of milliseconds for timeouts when connecting to the SMTP server. Default is 60s (60000ms).

send

A boolean indicating whether the email should be sent at the end of the function (default behaviour). If set to false, function returns the email object to the parent environment.

attach.files

A character vector of paths in the file system linking to files or *valid* URLs to be attached to the email (see details for more info on attaching URLs)

debug

A boolean indicating whether you wish to see detailed debug info

...

Optional arguments to be passed related to file attachments. See details for more info.

Details

The only mandatory value in the list 'smtp' is host.name that is the SMTP server address. A port number can also be provided via the list item 'port'. In case the SMTP server requires authorization, the parameter 'authenticate' must be set to TRUE and the list 'smtp' must include items 'user.name' and 'passwd'. If SSL or TLS encryption is required by the SMTP server, these can be indicated by setting a list item 'ssl' as TRUE or 'tls' as TRUE respectively. 'socketConnectionTimeout' and 'socketTimeout' allow overriding of the default 60000ms timeouts.

Using 'attach.files' you can attach files or web pages hosted on the web (for e.g. on Dropbox). Currently, URL hostnames must be prepended with http:// or https://. Two optional parameters relevant to attachments can be supplied. Parameter 'file.names' can be provided to assign names to the files listed in the parameter 'attach.files'. A description can be provided further as 'file.descriptions' to further describe the file. Both parameters must have the same length as 'attach.files'. In case attach.file is NULL, then these two parameters will be ignored.

HTML formatted emails can be sent by setting the parameters html and inline (if embedding images) to TRUE. The body of the email can either be a HTML string or point to a HTML file in the local file system.

Email headers can be set by passing a named list called headers, e.g., 'headers = list("X-Department"="Finance","X-Source"="Automated report")'.

Value

email A Java object of class org.apache.commons.mail.SimpleEmail or org.apache.commons.mail.MultiPartEmail

Note

For more examples, see https://github.com/rpremraj/mailR

Examples

sender <- "[email protected]"  # Replace with a valid address
recipients <- c("[email protected]")  # Replace with one or more valid addresses
email <- send.mail(from = sender,
                   to = recipients,
                   subject="Subject of the email",
                   body = "Body of the email",
                   smtp = list(host.name = "aspmx.l.google.com", port = 25),
                   authenticate = FALSE,
                   send = FALSE)
## Not run: email$send() # execute to send email or set parameter send= TRUE in send.mail()