curl (version 4.0)

send_mail: Send email

Description

Use the curl SMTP client to send an email. The message argument must be properly formatted RFC2822 email message with From/To/Subject headers and CRLF line breaks.

Usage

send_mail(mail_from, mail_rcpt, message, smtp_server = "localhost",
  verbose = TRUE, ...)

Arguments

mail_from

email address of the sender.

mail_rcpt

one or more recipient email addresses. Do not include names, these go into the message headers.

message

either a string or connection with (properly formatted) email message, including sender/recipient/subject headers. See example.

smtp_server

address of the SMTP server without the smtp:// part

verbose

print output

...

other options passed to handle_setopt. In most cases you will need to set a username and password to authenticate with the SMTP server.

Examples

Run this code
# NOT RUN {
# Message in RFC2822 format
message <- 'From: "Testbot" <jeroen@ocpu.io>
To: "Jeroen Ooms" <jeroenooms@gmail.com>
Subject: Hello there!

Hi Jeroen,
I am sending this email using curl.'


# Actually send the email
recipients <- c('test@opencpu.org', 'jeroenooms@gmail.com')
sender <- 'test@ocpu.io'
username <- 'mail@ocpu.io'
password <- askpass::askpass(paste("SMTP server password for", username))
send_mail(sender, recipients, smtp_server = 'smtp.mailgun.org',
  message = message, username = username, password = password)
# }

Run the code above in your browser using DataLab