{emayili} Support for Mailtrap

[This article was first published on R - datawookie, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The {emayili} package has adapters which make it simple to send email via a variety of services. For example, it caters specifically for ZeptoMail, MailerSend, Mailfence and Sendinblue. The latest version of {emayili}, 0.8.0 published on 23 April 2024, adds an an adapter for Mailtrap.

Account Setup

Before you can send emails via Mailtrap you will need to craete an account. Mailtrap offers both an API and SMTP servers. Finding the SMTP credentials on Mailtrap is not entirely simple. Well, it wasn’t for me. Select Sending Domains in the sidebar and then open the SMTP/API Settings tab.

On that page you’ll have access to the credentials for the transactional and bulk message streams.

There’s also a testing sandbox, and you can find the credentials for that by selecting Email Testing and Inboxes in the sidebar. Then open the SMTP Settings tab and choose one of the integrations. With the Postfix integration selected it’s simple to find the username and password.

Sending Mail via Mailtrap

Load {emayili} and create a Mailtrap SMTP server object. I’m storing my Mailtrap username and password in environment variables MAILTRAP_USERNAME and MAILTRAP_PASSWORD.



smtp <- mailtrap(

Now create a message object. The address specified in the From field needs to be the same one that was registered with Mailtrap (see Account Setup above).


msg <- envelope(
  to = "[email protected]",
  subject = "Test"
) %>%
  text("Hello there!")

Now send that message.

smtp(msg, verbose = TRUE)

Sandbox & Bulk Messaging

You can use the Sandbox and Bulk Messaging features by activating the sandbox and bulk arguments.

# Sandbox SMTP server.
sandbox <- mailtrap(sandbox = TRUE, ...)
# SandBulk Messaging SMTP server.
sandbox <- mailtrap(bulk = TRUE, ...)

If you are using another email service and you’d like it to be specifically supported by {emayili}, just create an issue and I’ll get it sorted.

To leave a comment for the author, please follow the link and comment on their blog: R - datawookie.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)