Skip to content

Instantly share code, notes, and snippets.

@MarkEdmondson1234
Last active March 18, 2024 14:06
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save MarkEdmondson1234/ddcac436cbdfd4557639522573bfc7b6 to your computer and use it in GitHub Desktop.
Save MarkEdmondson1234/ddcac436cbdfd4557639522573bfc7b6 to your computer and use it in GitHub Desktop.
Send an email via an R function using Mailgun
#' Email a user a report is ready
#'
#' Requires an account at Mailgun: https://mailgun.com
#' Pre-verification can only send to a whitelist of emails you configure
#'
#' @param email Email to send to
#' @param mail_message Any extra info
#'
#' @return TRUE if successful email sent
#' @import httr
#' @export
sendEmail <- function(email = "XXXXX@you.com",
mail_message = "Hello"){
url <- "https://api.mailgun.net/v3/sandbox5f2XXXXXXXa.mailgun.org/messages"
## username:password so api_key is all after the api:
api_key <- "key-c5957XXXXXXXXXXXbb9cf8ce"
the_body <-
list(
from="Mailgun Sandbox <postmaster@sandbox5XXXXXXXXa.mailgun.org>",
to=email,
subject="Mailgun from R",
text=mail_message
)
req <- httr::POST(url,
httr::authenticate("api", api_key),
encode = "form",
body = the_body)
httr::stop_for_status(req)
TRUE
}
@MarkEdmondson1234
Copy link
Author

Sorry I missed your comment @laresbernardo, they only just started sending notifications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment