Alfred-MailTo

A Workflow for Alfred 2.

Quickly select recipients from your Mac’s Contacts database and send them to your email client of choice. Also works with Groups/Distribution Lists.

Contents

Download and installation

You can install MailTo from GitHub releases.

Install by double-clicking MailTo.alfredworkflow.

Usage

Note: The first time you run MailTo, you will probably be asked to grant access to your Contacts. Obviously enough, if you refuse access, MailTo won’t work.

Quickstart

Use the @ keyword in Alfred to access MailTo and search your Mac’s Address Book.

Recipients will be suggested from matching contacts and groups in the accounts configured in your Contacts database.

Hit to autocomplete the recipient list from the selected result, or or ⌘+NUM to add the address to the recipient list and start composing a mail.

You can add multiple recipients by adding a comma between them.

Use mailto to view/change settings.

All options

Email clients

In theory, any email client should work, as MailTo uses a mailto: URI to call your email client.

In practice, support for mailto: varies widely between clients. Pretty much any client will accept a URI containing only email addresses, but many choke if the URI also contains recipients’ names, e.g. Bob Jones <bob.jones@example.com> instead of just bob.jones@example.com.

MailTo knows how to handle all the clients listed below and will automatically fall back to email addresses only if the client is known to choke on names.

If your email weapon-of-choice isn’t working properly, try forcing MailTo to use email addresses only (enter mailto in Alfred and toggle Format to Email Only in MailTo the Configuration), and file a bug report or submit a pull request if you’ve got it working yourself.

Supported email clients

The following email clients currently work “out of the box”:

Unsupported clients

The following do not work:

Other clients

Anything not listed above hasn’t been tested because I don’t own a copy to test with.

If your client doesn’t work with the default settings, you can try your hand at adding rules for that client by editing the client_rules.json file in MailTo’s data directory. To access the file, open the configuration options with mailto and select Edit Client Formatting Rules. client_rules.json will be revealed in Finder.

The file is well documented, and you can try different combinations of options to see if you can find one that works with your client. If you do, please share them in a GitHub issue or pull request (add the configuration to the default client_rules.json in the src directory). A sample configuration looks like this (this is the default configuration for MailMate):

{
        "com.freron.MailMate": {
                "spaces": true,
                "names": true,
                "mime": false,
                "no_commas": false,
                "inline_to": false
        },
        // other apps here
        // ...
}

Note: To configure an app, you must use its bundle ID, not its name (i.e. com.freron.MailMate, not MailMate).

You can use MailTo’s configuration screen to get the bundle ID of an application:

  1. Use mailto to bring up the configuration menu, and choose Email Client: …. This will display a list off all compatible apps on your system.
  2. Search or scroll down the list to select the app you want.
  3. Hold to display its bundle ID as the subtitle or press ⌘+C to copy the bundle ID to the pasteboard. ⌘+L will also display the bundle ID in Alfred’s Large Text window.

Alternatively, you can use the following command in Terminal to get the bundle ID of an application:

mdls -name kMDItemCFBundleIdentifier -raw /Applications/MailMate.app
# com.freron.MailMate

Supported account types

MailTo uses the official Address Book API to read your contacts.

The following account types are definitely supported:

I don’t know about any other account types, as I don’t have any to test with…

Please let me know if you have a different kind of account, e.g. Exchange or LDAP, and whether or not it works.

Google Contacts

Groups are currently not synced properly between Google accounts and Contacts.app. Groups created in Contacts.app in a Google account become a single, empty contact in your Google Contacts; groups in Google Contacts are ignored by Contacts.app.

This is a limitation of the Contacts.app–Google Contacts integration, not of MailTo.

Miscellany

Configuring groups and distribution lists

You can use groups in your Contacts database as mailing lists/distribution lists. When you add a contact to a group, their primary email address will be used when you send an email to that group (the primary email is the one listed first in Contacts.app).

If you’d like to change the email address associated with a group, open Contacts.app and select the Edit > Edit Distribution List… menu item:

Select the group you’d like to edit from the list on the left and then click on the email addresses you’d like to associate with the group:

In this example, I’ve associated Jürgen’s versuchgroup@example.com email address with the group. If you watch the demo animation, you can see that when I send an email to Test Group, that’s the address that’s used for Jürgen.

Fluid apps

Fluid is an application that turns web applications into native applications. It generates so-called “single-session browsers”, which are basically browser apps designed to visit only one website.

By default, all Fluid-generated apps can handle mailto: URIs (and will show up in MailTo’s list of email clients), but only via Gmail (which is pre-configured by Fluid).

To add a different webmail service, first you need to figure out the URL to send the email address(es) to.

Roundcube webmail

For a Roundcube installation, it would be something like:

https://mail.example.com/?_task=mail&_action=compose&to=

Once you’ve got your URL, open your Fluid app’s Preferences and go to URL Handler Preferences. Add a new group for your webmail service and add the pattern mailto:*. Then copy the JavaScript from the Gmail > mailto:* script box into your own mailto:* handler’s box. Finally, change the URL in the outURLString line to your own webmail’s URL. For a Roundcube installation, it’d look like this:

function transform(inURLString) {
                inURLString = inURLString.replace('mailto:', '');
                inURLString = inURLString.replace('&amp;', '&');

                var argStr = '';
                var splits = inURLString.split('?');

                var emailAddr = null;
                var args = {};
                if (splits.length > 0) emailAddr = splits[0];
                if (splits.length > 1) argStr = splits[1];

                var outURLString = 'https://mail.example.com/?_task=mail&_action=compose&to=' + emailAddr;

                if (argStr.length > 0) outURLString += '&' + argStr;
                return outURLString;
}

Don’t forget to deactivate (uncheck) the Gmail mailto:* script!

Updates

MailTo has a built-in updater and will offer to update itself via GitHub if a newer version is available.

You can turn off update notifications if you prefer (by default, MailTo will show an update notification in your results list).

Bugs, feature requests, suggestions

Please report any bugs and submit any feature requests via GitHub issues or in the thread on the Alfred Forum.

Thanks, licensing etc.