Skip to content

Commit

Permalink
feat: Add mailtrap server
Browse files Browse the repository at this point in the history
  • Loading branch information
datawookie committed Apr 23, 2024
1 parent cb0f2f7 commit d90c661
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@ SystemRequirements: The function render() requires Pandoc (http://pandoc.org).
To use PGP/GnuPG encryption requires gpg.
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
KeepSource: true
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export(local)
export(mailersend)
export(mailfence)
export(mailgun)
export(mailtrap)
export(normalise)
export(parties)
export(priority)
Expand Down
30 changes: 30 additions & 0 deletions R/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,33 @@ smtpbucket <- function(...) {

eval(fcall, parent.frame())
}

#' @rdname server
#'
#' @section SMTP Bucket:
#'
#' SMTP Bucket is a fake SMTP server that captures all the messages it receives
#' and makes them available through a website or REST API.
#'
#' @export
#'
#' @examples
#'
#' # SMTP Bucket server.
#' smtp <- smtpbucket()
mailtrap <- function(sandbox = FALSE, bulk = FALSE, ...) {
fcall <- match.call(expand.dots = TRUE)

fcall[[1]] <- server
fcall$port <- 587

if (sandbox) {
fcall$host <- "sandbox.smtp.mailtrap.io"
} else if (bulk) {
fcall$host <- "bulk.smtp.mailtrap.io"
} else {
fcall$host <- "live.smtp.mailtrap.io"
}

eval(fcall, parent.frame())
}
11 changes: 11 additions & 0 deletions man/server.Rd

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

8 changes: 8 additions & 0 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ SMTP_USERNAME_SENDINBLUE <- Sys.getenv("SENDINBLUE_SMTP_USERNAME")
SMTP_PASSWORD_SENDINBLUE <- Sys.getenv("SENDINBLUE_SMTP_PASSWORD")
SMTP_USERNAME_MAILERSEND <- Sys.getenv("MAILERSEND_SMTP_USERNAME")
SMTP_PASSWORD_MAILERSEND <- Sys.getenv("MAILERSEND_SMTP_PASSWORD")
SMTP_USERNAME_MAILTRAP <- Sys.getenv("MAILTRAP_SMTP_USERNAME")
SMTP_PASSWORD_MAILTRAP <- Sys.getenv("MAILTRAP_SMTP_PASSWORD")

EMAIL_FROM <- ifelse(is.na(SMTP_USERNAME_GMAIL), "alice@gmail.com", SMTP_USERNAME_GMAIL)
EMAIL_TO <- ifelse(is.na(SMTP_USERNAME_GMAIL), "bob@yahoo.com", SMTP_USERNAME_GMAIL)
Expand Down Expand Up @@ -135,6 +137,12 @@ smtp_mailersend <- mailersend(

smtp_smtpbucket <- smtpbucket()

smtp_mailtrap <- mailtrap(
sandbox = TRUE,
username = SMTP_USERNAME_MAILTRAP,
password = SMTP_PASSWORD_MAILTRAP
)

# TEMPLATE ---------------------------------------------------------------------

TEMPLATE_HTML_CONTENT <- "<p>Hello {{ name }}!</p>"
Expand Down

0 comments on commit d90c661

Please sign in to comment.