{emayili} Encrypted Email with Mailfence

[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.

In the previous post I ran through the process of setting up a Mailfence account for encrypting emails. In this post I show how Mailfence can be used with the {emayili} package for sending encrypted email from R.

Create an account on Mailfence. If you want to use Mailfence with {emayili} (or another desktop email client), then you’ll need to have access to the Mailfence SMTP server. Unfortunately this is not available on the free plan, however, Mailfence are happy to give you a 15 day free trial to test it out. That should be ample time to decide whether or not this is a good solution for you.

Exporting a Personal Encryption Key

Before you can use Mailfence with {emayili} (or any other local email client) you’ll need to export a private key from Mailfence and import it into your local keychain.

It is possible to use a Mailfence account from {emayili} without importing a private key onto your local keychain. But if you want to encrypt messages with the same key that’s being used in your Mailfence account then this is an indispensable step.
  1. Go to SettingsMessagesEncryption.
  2. Click on the link for the key under My personal keys. You will likely only have one key listed here, but in principle there’s no reason why you should not have more. Choose the key that you want to export.
  3. Click on the Export link.

This will initiate the download of a file with a .asc extension. In my case the file was called Andrew_Collier_priv.asc.

Import into Local Keychain

Now import the contents of this file onto your GPG keychain. You’ll need to provide the passphrase for the key.

gpg --import Andrew_Collier_priv.asc

gpg: key 71B43FBB68FABD19: secret key imported
gpg: Total number processed: 2
gpg:              unchanged: 2
gpg:       secret keys read: 1
gpg:   secret keys imported: 1

Confirm that the key has been added.

gpg --list-keys

pub   rsa4096 2021-11-26 [SC]
uid           [ultimate] Andrew B. Collier <[email protected]>
sub   rsa4096 2021-11-26 [E]

pub   rsa4096 2022-04-03 [SC] [expires: 2025-04-02]
uid           [ unknown] Andrew Collier <[email protected]>
sub   rsa4096 2022-04-03 [E] [expires: 2025-04-02]

Using Mailfence with {emayili}

Right, you’re ready to use Mailfence with {emayili}. You can immediately do this via the Mailfence web interface, but I’m more interested in doing it via {emayili}.



[1] '0.7.9'

Create a server object using the mailfence() function.

smtp <- smtp <- mailfence(
  username = "datawookie",
  password = Sys.getenv("MAILFENCE_PASSWORD")

Create a message. I’m going to just send this to my work email address.

msg <- envelope(
  to = "[email protected]",
  from = "[email protected]",
  subject = "Database Password (keep this safe!)"
) %>%
  text("Your database password is pmbZ8BZfrim%K!n9.")

Now encrypt it.

msg <- msg %>% encrypt()



That seemed to be successful. I’ll flip over to my email client to check.

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)