Send emails from R with mailgun

Send emails from R with mailgun

Why?

Until now I’ve been sending emails with R using my Gmail account. This works, but configuring mailR for the first time is always a pain. A few days ago @marked told me about mailgun and how to use it. The great thing is that you only need httr to use it.

How?

Using @marked as my base, I created a tiny R package to make using mailgun even easier:

drat::addRepo(account = "Ignacio", alturl = "https://drat.ignacio.website/")
install.packages("IMmailgun")
library(IMmailgun)
# Create an IMmailgun object
email_client <- mailgun$new(url = url, api_key = api_key, from = from)

# Send a simple email 
email_client$sendEmail(to = c("ignacio82@gmail.com", "ignacio@protonmail.com"), 
                       subject = "Test", plaintext = "Hola a todos!")

# Send an attachment

email_client$sendEmail(to = "ignacio82@gmail.com", 
                       subject = "Test with attachment", 
                       plaintext = "Check the attachment",
                       attachment = './README.md')

# Get stats

email_client$stats()
Ignacio Martinez avatar
About Ignacio Martinez
research economist, tech enthusiast
comments powered by Disqus