| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/email.R |
| 3 |
\name{send_mail} |
| 4 |
\alias{send_mail} |
| 5 |
\title{Send email} |
| 6 |
\usage{ |
| 7 |
send_mail( |
| 8 |
mail_from, |
| 9 |
mail_rcpt, |
| 10 |
message, |
| 11 |
smtp_server = "smtp://localhost", |
| 12 |
use_ssl = c("try", "no", "force"), |
| 13 |
verbose = TRUE, |
| 14 |
... |
| 15 |
) |
| 16 |
} |
| 17 |
\arguments{ |
| 18 |
\item{mail_from}{email address of the sender.} |
| 19 |
|
| 20 |
\item{mail_rcpt}{one or more recipient email addresses. Do not include names, |
| 21 |
these go into the \code{message} headers.} |
| 22 |
|
| 23 |
\item{message}{either a string or connection with (properly formatted) email |
| 24 |
message, including sender/recipient/subject headers. See example.} |
| 25 |
|
| 26 |
\item{smtp_server}{hostname or address of the SMTP server, or, an |
| 27 |
\verb{smtp://} or \verb{smtps://} URL. See "Specifying the server, port, |
| 28 |
and protocol" below.} |
| 29 |
|
| 30 |
\item{use_ssl}{Request to upgrade the connection to SSL using the STARTTLS command, |
| 31 |
see \href{https://curl.se/libcurl/c/CURLOPT_USE_SSL.html}{CURLOPT_USE_SSL} |
| 32 |
for details. Default will try to SSL, proceed as normal otherwise.} |
| 33 |
|
| 34 |
\item{verbose}{print output} |
| 35 |
|
| 36 |
\item{...}{other options passed to \code{\link[=handle_setopt]{handle_setopt()}}. In most cases |
| 37 |
you will need to set a \code{username} and \code{password} or \code{login_options} |
| 38 |
to authenticate with the SMTP server, see details.} |
| 39 |
} |
| 40 |
\description{ |
| 41 |
Use the curl SMTP client to send an email. The \code{message} argument must be |
| 42 |
properly formatted \href{https://www.rfc-editor.org/rfc/rfc2822}{RFC2822} email message with From/To/Subject headers and CRLF |
| 43 |
line breaks. |
| 44 |
} |
| 45 |
\section{Specifying the server, port, and protocol}{ |
| 46 |
|
| 47 |
|
| 48 |
The \code{smtp_server} argument takes a hostname, or an SMTP URL: |
| 49 |
|
| 50 |
\itemize{ |
| 51 |
\item \code{mail.example.com} - hostname only |
| 52 |
\item \code{mail.example.com:587} - hostname and port |
| 53 |
\item \verb{smtp://mail.example.com} - protocol and hostname |
| 54 |
\item \verb{smtp://mail.example.com:587} - full SMTP URL |
| 55 |
\item \verb{smtps://mail.example.com:465} - full SMTPS URL |
| 56 |
} |
| 57 |
|
| 58 |
By default, the port will be 25, unless \verb{smtps://} is specified--then |
| 59 |
the default will be 465 instead. |
| 60 |
|
| 61 |
For internet SMTP servers you probably need to pass a |
| 62 |
\href{https://curl.se/libcurl/c/CURLOPT_USERNAME.html}{username} and |
| 63 |
\href{https://curl.se/libcurl/c/CURLOPT_PASSWORD.html}{passwords} option. |
| 64 |
For some servers you also need to pass a string with |
| 65 |
\href{https://curl.se/libcurl/c/CURLOPT_LOGIN_OPTIONS.html}{login_options} |
| 66 |
for example \code{login_options="AUTH=NTLM"}. |
| 67 |
} |
| 68 |
|
| 69 |
\section{Encrypting connections via SMTPS or STARTTLS}{ |
| 70 |
|
| 71 |
|
| 72 |
There are two different ways in which SMTP can be encrypted: SMTPS servers |
| 73 |
run on a port which only accepts encrypted connections, similar to HTTPS. |
| 74 |
Alternatively, a regular insecure smtp connection can be "upgraded" to a |
| 75 |
secure TLS connection using the STARTTLS command. It is important to know |
| 76 |
which method your server expects. |
| 77 |
|
| 78 |
If your smtp server listens on port 465, then use a \verb{smtps://hostname:465} |
| 79 |
URL. The SMTPS protocol \emph{guarantees} that TLS will be used to protect |
| 80 |
all communications from the start. |
| 81 |
|
| 82 |
If your email server listens on port 25 or 587, use an \verb{smtp://} URL in |
| 83 |
combination with the \code{use_ssl} parameter to control if the connection |
| 84 |
should be upgraded with STARTTLS. The default value \code{"try"} will |
| 85 |
\emph{opportunistically} try to upgrade to a secure connection if the server |
| 86 |
supports it, and proceed as normal otherwise. |
| 87 |
} |
| 88 |
|
| 89 |
\examples{ |
| 90 |
\dontrun{# Set sender and recipients (email addresses only) |
| 91 |
recipients <- readline("Enter your email address to receive test: ") |
| 92 |
sender <- '[email protected]' |
| 93 |
|
| 94 |
# Full email message in RFC2822 format |
| 95 |
message <- 'From: "R (curl package)" <[email protected]> |
| 96 |
To: "Roger Recipient" <[email protected]> |
| 97 |
Subject: Hello R user! |
| 98 |
|
| 99 |
Dear R user, |
| 100 |
|
| 101 |
I am sending this email using curl.' |
| 102 |
|
| 103 |
# Send the email |
| 104 |
send_mail(sender, recipients, message, smtp_server = 'smtps://smtp.gmail.com', |
| 105 |
username = 'curlpackage', password = 'qyyjddvphjsrbnlm')} |
| 106 |
} |