# Before sending out an email through
# SMTP, we need an `email_message`
# object; for the purpose of a simple
# example, we can use the function
# `prepare_test_message()` to create
# a test version of an email (although
# we'd normally use `compose_email()`)
email <- prepare_test_message()
# The `email` message can be sent
# through the `smtp_send()` function
# so long as we supply the appropriate
# credentials; The following three
# examples provide scenarios for both
# the creation of credentials and their
# retrieval within the `credentials`
# argument of `smtp_send()`
# (1) Providing the credentials info
# directly via the `creds()` helper
# (the most secure means of supplying
# credentials information)
# email %>%
# smtp_send(
# from = "sender@email.com",
# to = "recipient@email.com",
# credentials = creds(
# provider = "gmail",
# user = "sender@email.com")
# )
# (2) Using a credentials key (with
# the `create_smtp_creds_key()` and
# `creds_key()` functions)
# create_smtp_creds_key(
# id = "gmail",
# user = "sender@email.com",
# provider = "gmail"
# )
# email %>%
# smtp_send(
# from = "sender@email.com",
# to = "recipient@email.com",
# credentials = creds_key(
# "gmail"
# )
# )
# (3) Using a credentials file (with
# the `create_smtp_creds_file()` and
# `creds_file()` functions)
# create_smtp_creds_file(
# file = "gmail_secret",
# user = "sender@email.com",
# provider = "gmail"
# )
# email %>%
# smtp_send(
# from = "sender@email.com",
# to = "recipient@email.com",
# credentials = creds_file(
# "gmail_secret")
# )
Run the code above in your browser using DataLab