Skip to content

Commit

Permalink
SMTP credentials/sending changes (#108)
Browse files Browse the repository at this point in the history
* Add `verbose` arg to `smtp_send()`

* Remove certain args from `creds_anonymous()`

* Remove unused `sender_name` option

* Remove docs for removed `password` arg

This also corrects a nearby spelling error.
  • Loading branch information
rich-iannone authored Nov 18, 2019
1 parent 4fbd99f commit f12c907
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 55 deletions.
14 changes: 2 additions & 12 deletions R/create_credentials.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#' and `port` parameters are the address and port for the SMTP server;
#' `use_ssl` is an option as to whether to use SSL: supply a `TRUE` or `FALSE`
#' value.
#' @param sender_name An option to specify a sender name. This isn't always
#' visible to the recipient, however, as some SMTP servers will suppress this.
#'
#' @examples
#' # Create a credentials file to make it
Expand All @@ -37,8 +35,7 @@ create_smtp_creds_file <- function(file,
provider = NULL,
host = NULL,
port = NULL,
use_ssl = NULL,
sender_name = NULL) {
use_ssl = NULL) {

# nocov start

Expand All @@ -50,7 +47,6 @@ create_smtp_creds_file <- function(file,
create_credentials_list(
provider = provider,
user = user,
sender_name = sender_name,
host = host,
port = port,
use_ssl = use_ssl
Expand Down Expand Up @@ -105,8 +101,7 @@ create_smtp_creds_key <- function(id,
provider = NULL,
host = NULL,
port = NULL,
use_ssl = NULL,
sender_name = NULL) {
use_ssl = NULL) {

# nocov start

Expand All @@ -130,7 +125,6 @@ create_smtp_creds_key <- function(id,
create_credentials_list(
provider = provider,
user = user,
sender_name = sender_name,
host = host,
port = port,
use_ssl = use_ssl
Expand Down Expand Up @@ -167,7 +161,6 @@ create_smtp_creds_key <- function(id,
create_credentials_list <- function(provider,
user,
password = getPass::getPass("Enter the SMTP server password: "),
sender_name,
host,
port,
use_ssl) {
Expand All @@ -176,7 +169,6 @@ create_credentials_list <- function(provider,
user = user,
password = password,
provider = provider,
sender_name = sender_name,
host = host,
port = port,
use_ssl = use_ssl
Expand All @@ -189,7 +181,6 @@ create_credentials_list <- function(provider,
creds_internal <- function(user = NULL,
password = NULL,
provider = NULL,
sender_name = NULL,
host = NULL,
port = NULL,
use_ssl = NULL) {
Expand Down Expand Up @@ -217,7 +208,6 @@ creds_internal <- function(user = NULL,
# Generate the credentials list
list(
version = schema_version,
sender_name = sender_name,
host = host,
port = port,
use_ssl = use_ssl,
Expand Down
19 changes: 4 additions & 15 deletions R/creds_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' The [creds()] credential helper allows for manual specification of SMTP
#' configuration and authentication.
#'
#' The [creds_anonymous()] credential helper is similiar to [creds()] but
#' The [creds_anonymous()] credential helper is similar to [creds()] but
#' provides convenient defaults for authenticating anonymously with an SMTP
#' server.
#'
Expand All @@ -23,15 +23,10 @@
#'
#' @param user The username for the email account. Typically, this is the email
#' address associated with the account.
#' @param password This argument is available in the [creds_anonymous()] and
#' isn't typically used unless an 'anonymous' password requires a specific
#' value (e.g., "anonymous" as the password itself).
#' @param provider An optional email provider shortname for autocompleting STMP
#' configuration details (the `host`, `port`, `use_ssl` options). Options
#' currently include `gmail`, `outlook`, and `office365`. If nothing is
#' provided then values for `host`, `port`, and `use_ssl` are expected.
#' @param sender_name An option to specify a sender name. This isn't always
#' visible to the recipient, however, as some SMTP servers will suppress this.
#' @param host,port,use_ssl Configuration info for the SMTP server. The `host`
#' and `port` parameters are the address and port for the SMTP server;
#' `use_ssl` is an option as to whether to use SSL: supply a `TRUE` or `FALSE`
Expand All @@ -54,7 +49,6 @@ NULL
#' @export
creds <- function(user = NULL,
provider = NULL,
sender_name = NULL,
host = NULL,
port = NULL,
use_ssl = TRUE) {
Expand All @@ -64,7 +58,6 @@ creds <- function(user = NULL,
create_credentials_list(
provider = provider,
user = user,
sender_name = sender_name,
host = host,
port = port,
use_ssl = use_ssl
Expand All @@ -76,20 +69,16 @@ creds <- function(user = NULL,

#' @rdname credential_helpers
#' @export
creds_anonymous <- function(user = "anonymous",
password = NULL,
provider = NULL,
sender_name = NULL,
creds_anonymous <- function(provider = NULL,
host = NULL,
port = NULL,
use_ssl = TRUE) {

creds_list <-
creds_internal(
user = user,
password = password,
user = NULL,
password = NULL,
provider = provider,
sender_name = sender_name,
host = host,
port = port,
use_ssl = use_ssl
Expand Down
9 changes: 7 additions & 2 deletions R/smtp_send.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
#' @param creds_file An option to specify a credentials file. As this argument
#' is deprecated, please consider using `credentials = creds_file(<file>)`
#' instead.
#' @param verbose Should verbose output from the internal curl `send_mail()`
#' call be printed? While the username and password will likely be echoed
#' during the exchange, such information is encoded and won't be stored on
#' the user's system.
#'
#' @examples
#' # Before sending out an email through
Expand Down Expand Up @@ -126,7 +130,8 @@ smtp_send <- function(email,
cc = NULL,
bcc = NULL,
credentials = NULL,
creds_file = "deprecated") {
creds_file = "deprecated",
verbose = FALSE) {

# Verify that the `message` object
# is of the class `email_message`
Expand Down Expand Up @@ -208,7 +213,7 @@ smtp_send <- function(email,
message = email_qp,
smtp_server = paste0(credentials$host, ":", credentials$port),
use_ssl = credentials$use_ssl,
verbose = FALSE,
verbose = verbose,
username = credentials$user,
password = credentials$password
)
Expand Down
5 changes: 1 addition & 4 deletions man/create_smtp_creds_file.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions man/create_smtp_creds_key.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 5 additions & 12 deletions man/credential_helpers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion man/smtp_send.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions tests/testthat/test-credentials.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ test_that("utility functions for credentials work properly", {
provider = NULL,
user = "[email protected]",
password = "testpass",
sender_name = "testsender",
host = "smtp.example.com",
port = 465,
use_ssl = TRUE
Expand All @@ -21,7 +20,7 @@ test_that("utility functions for credentials work properly", {
credentials_list_1 %>%
names() %>%
expect_equal(
c("version", "sender_name", "host", "port", "use_ssl", "user", "password")
c("version", "host", "port", "use_ssl", "user", "password")
)

# Expect a specific value for `credentials_list_1$version`
Expand All @@ -34,7 +33,6 @@ test_that("utility functions for credentials work properly", {
provider = "gmail",
user = "[email protected]",
password = "testpass",
sender_name = "testsender",
host = NULL,
port = NULL,
use_ssl = NULL
Expand All @@ -44,7 +42,7 @@ test_that("utility functions for credentials work properly", {
credentials_list_2 %>%
names() %>%
expect_equal(
c("version", "sender_name", "host", "port", "use_ssl", "user", "password")
c("version", "host", "port", "use_ssl", "user", "password")
)

# Expect that the `host`, `port`, and `use_ssl` elements
Expand All @@ -60,7 +58,6 @@ test_that("utility functions for credentials work properly", {
provider = NULL,
user = "[email protected]",
password = "testpass",
sender_name = "testsender",
host = NULL,
port = NULL,
use_ssl = NULL
Expand Down

0 comments on commit f12c907

Please sign in to comment.