{emayili} Sending Email from Shiny

The {emayili} package for sending emails from R works well within a Shiny app. You just need to set it up right.

I’ve added a simple demonstration script to the latest version of {emayili}. You’ll find it in the inst/shiny/send-message directory.


Probably the easiest way to set this up will be to create a copy of the app in a new folder. The app gets the details of the SMTP server and the account credentials from environment variables. So you’ll need to edit an .Renviron file in the same directory as the app and add values for those variables. Something like this:


Now deploy the app to shinyapps.io.


When the deploy is complete (and assuming that it’s successful) the app should launch in your browser.


This is what the app should look like.

Demo Shiny application in browser, showing button to send a message.

It displays:

  • the IP address of the server on which it is running
  • the DNS name and port of the configured SMTP server (if these are absent then it means that the app is not picking up your environment variables).

Pressing the button will dispatch an email from the address specified in the SMTP_USERNAME environment variable to the same address.

Upon receipt the email should look something like this.

Email sent from Shiny application.

The IP address in the email will agree with that displayed in the app, confirming that it was indeed sent from the app! 🚀