<commit_before># Processing Emails with Scripts

## Setup

Sometimes I need to set up a server to process incoming email with a script. Here's how I do it.

Running Ubuntu 14.04 to start with. Make sure your server has a fully qualified domain name and whatnot. The following commands are assumed to be run as root.

First, install exim:

   apt-get install exim4

Yay, we've installed the exim mail service. Now we need to reconfigure it for our needs:

    dpkg-reconfigure exim4-config

Select "internet site" and type in the FQDN of the server (whatever.com) when prompted. Do **not** split config files.

Now we're going to enable using the "address_pipe" which allows routing emails to scripts:

    echo "SYSTEM_ALIASES_PIPE_TRANSPORT = address_pipe" > /etc/exim4.conf.localmacros

Because we've made a config change, you have to run:

    update-exim4.conf

Okay now we'll add an "alias" that'll forward mail to a script:

    nano /etc/aliases

At the bottom of this, enter something in this format:

    address:|/path/to/script

That means messages to <EMAIL> will be piped to that script as STDIN.

Make sure `/path/to/script` is `chmod +x` and in a readable folder and anything it refers to has an absolute path.

    service exim4 restart

Not sure if you really need to restart exim4, but do it anyway just to be sure.

To see if it works, send a test email to that address, via a command like:
<commit_msg>updating a few typos and writing a little more<commit_after># Processing Emails with Scripts

## Setup

Sometimes I need to set up a server to process incoming email with a script. Here's how I do it.

Running Ubuntu 14.04 to start with. Make sure your server has a fully qualified domain name (whatever.com) and whatnot. The following commands are assumed to be run as root.

First, install exim:

    apt-get install exim4

Yay, we've installed the exim mail service. Now we need to reconfigure it for our needs:

    dpkg-reconfigure exim4-config

Select "internet site" and type in the FQDN of the server (whatever.com) when prompted. Do **not** split config files.

Now we're going to enable using the "address_pipe" which allows routing emails to scripts:

    echo "SYSTEM_ALIASES_PIPE_TRANSPORT = address_pipe" > /etc/exim4.conf.localmacros

Because we've made a config change, you have to run:

    update-exim4.conf

Okay now we'll add an "alias" that'll forward mail to a script:

    nano /etc/aliases

At the bottom of this, enter something in this format:

    address:|/path/to/script

That means messages to <EMAIL> will be piped to that script as STDIN.

You can change that "address" to whatever you want as long as it doesn't contain any spaces, I believe. Has to resolve into a valid email address.

Make sure `/path/to/script` is `chmod +x` and in a readable folder and anything it refers to has an absolute path.

    service exim4 restart

Not sure if you really need to restart exim4, but do it anyway just to be sure.

To see if it works, send a test email to that address, via a command like:

{'fraction_non_alphanumeric': 0.05623150279513318, 'fraction_numerical': 0.006576783952647156, 'mean_word_length': 3.7236024844720497, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2028825', 'n_tokens_mistral': 923, 'n_tokens_neox': 870, 'n_words': 476}