Configuring the Alpine email client

Over the years I have used many different email clients, the more recent ones having graphical interfaces like Kmail and Thunderbird. I have also used text mode clients such as mailx, Mutt, and Pine. Of the three, I liked Pine; it just seemed to fit my style of working.

Mostly out of curiosity I wanted to revisit Pine and see whether it would work for me to help resolve a bit of a problem I sometimes have when traveling. Some ISPs do not like outbound email to leave their network unless it is routed through their own email servers. But of course you also need to have an account with the ISP in order to send outbound email through their servers making it difficult to send email from those ISPs.

This blocking of outbound port 25 for email is intentional and is most times used to prevent hijacked hosts from acting as spam-bots and sending email out over the ISPs network. Such a situation could result in the ISP being flagged as the source of spam and being added to spam-blocking web sites thus preventing legitimate email from reaching its proper destination. So in some places during my travels I have been unable to easily send email from my laptop or other devices that connected to the local ISP via hard-wire or WiFi.

I wanted to use an email client that I could run as an email user on my own email server, thus eliminating the issue of blocked outbound email. In other words, I would use SSH login to my email server from wherever I might be at any given time. Once logged in I would simply start the text mode mail client and receive and send email directly from my own email server, this eliminating any outbound port 25 blocking issues.

I remembered that I could do that with Pine which I used for a while about 15 years ago. I liked it so thought I would give it another try.

Pine was written at the University of Washington in 1992. After some research I discovered that Pine is no longer supported and has not been updated since 2005. It has been replaced by Alpine, which was also written at UW. Alpine was intended to be a complete rewrite and a replacement for Pine. The most current version of Alpine as of this writing is 2.21 which was released in March of 2017 which is very recent. Naturally I decided to try Alpine.

The user account

Although Alpine can be used to remotely access an email server, I wanted to install it directly on the server and use it there. This means that the user must login to the mail server remotely using a valid login ID. This brings up an issue because email accounts are generally not login accounts.

student:x:1008:1008:Student email account:/home/student:/sbin/nologin

Listing 1: A typical email account uses the nologin shell to prevent the user from logging into the mail server.

Listing 1 shows the /etc/passwd entry for a typical email user, student. The /sbin/nologin shell is used to prevent the user from logging into the email server as a regular user with the results shown in Listing 2.

This account is currently not available.
Connection to bh closed.

Listing 2: You will get this error message when trying to login with the nologin shell.

To convert the student account to a login account, change the shell to any regular login shell. I like bash so that is what I changed the user shell to as shown in Listing 3. This change does not affect the use of the account for email.

student:x:1008:1008:Student email account:/home/student:/bin/bash

Listing 3: The user account after changing the default shell to BASH.

Working as root, I could have used the chsh command to change the user shell for student, but I prefer to just edit the /etc/passwd file directly using a text editor. When creating a new email account, the default shell for Linux is bash so no changes would be needed. I tested my new email account by using it to login to the email server.

I then configured the email server to add the student account. I use SendMail so I added the line shown in Listing 4 to the /etc/mail/virtusertable file. To activate the new email address I ran the make command from within the /etc/mail directory and restarted SendMail. Other email servers may use different methods to add a new email user.              student

Listing 4: Add this line to the /etc/mail/virtusertable file to add the student user to the SendMail server.

I sent a test message to the student user to verify that the account can receive emails. Even without using an email client, this can be checked by looking at the content of the /var/spool/mail/student file to verify that the test message is there. All of the files in the /var/spool/mail directory are inboxes for email users.

Alpine installation and configuration

Alpine is easy to install on CentOS which is my preferred server distro although I sometimes use Fedora as a server. Alpine for CentOS is located in the Extra Packages for Enterprise Linux (EPEL) repository so you may need to install the EPEL package if it has not been already. Alpine is located in the standard Fedora repositories, so there is no need to add an additional repo to your system if you use Fedora. For my CentOS email server I used the command in Listing 5 to install Alpine.

yum -y install alpine

Listing 5: Install Alpine on CentOS using YUM.

I could have downloaded the source and build it myself but using the packaged version is so much faster and easier.

To begin using Alpine, I logged into the email server as the student user. I typed the command alpine to start the email client. The first thing Isaw was a message indicating that Alpine is creating the ~/mail subdirectory in which it will store its mail. This might create a conflict with other email clients, but is easily resolved; as I will explain below.

Next, Alpine displays a Welcome page. This page is only displayed the first time Alpine is run. The maintainers have a request on the Welcome page that you press the “Return” (Enter) key to automatically send an email to the Alpine developers so they have some idea of how many people are using the software. I always do that myselfto ensure they know that there is enough interest to continue to maintain Alpine. I then pressed the Enter key and the next thing displayed was the Alpine Main Menu as shown in Listing 6.

ALPINE 2.21      MAIN MENU         Folder: INBOX 1 Message

          ?      HELP              - Get help using Alpine

          C      COMPOSE MESSAGE   - Compose and send a message

          I      MESSAGE INDEX     - View messages in current folder

          L      FOLDER LIST       - Select a folder to view

          A      ADDRESS BOOK      - Update address book

          S      SETUP             - Configure Alpine Options

          Q      QUIT              - Leave the Alpine program

<snip empty lines>

                       For Copyright information press "?"

? Help                   P PrevCmd            R RelNotes
O OTHER CMDS > [Index]   N NextCmd            K KBLock

Listing 6: The Alpine Main Menu

Alpine starts up with the Inbox as the default folder. The Inbox is actually the file /var/spool/mail/student that contains all of the mail for the account’s inbox. Email that is moved from the inbox to another folder is stored in the corresponding directory in ~/home/mail.

Note in Listing 6 that there is already one email in the student inbox. There are two lines of help at the bottom of the page that show the commands pertinent to the current menu page. Some commands can be issued from almost any menu by typing the corresponding letter. Be careful as sometimes different commands may use the same letter shortcut depending upon which menu page you are on. The help lines at the bottom can guide you. Be sure to check out O for Other commands available in each menu screen.

I typed I to view the email in the inbox. I could have also used the arrow keys to highlight “MESSAGE INDEX” and then pressed the Enter key to accomplish the same thing.

To view the email in the inbox, I highlight it and then press the Enter key. Then I typed < to return to the inbox, M to return to the main menu.

Type S and then C to get to the Configuration menu. There is very little that needs to change here because Alpine is running local to the server but I did set the signature to my name. I also changed the default location for sent messages from sent-messages to “Sent” which is where Thunderbird stores sent messages. Note that it is not necessary to configure an outbound SMTP server because the localhost is used by default.

At this point I fixed the client email location problem. Clients like Thunderbird store email in folders located in the user’s home directory (~). By default, Alpine stores email in folders it creates in ~/mail, except for the Inbox. So I needed to ensure that Thunderbird and Alpine could both access the email folders. This issue cannot be solved using the Alpine or Thunderbird configuration options. Specifying the user’s home directory (~) for the default Collection List – group of folders – results in Alpine trying to create the user’s home directory which already exists; this causes the change to fail. There is no option to change the default folder location without attempting to create it.

Linux provides a simple solution. I created hard links in the ~/mail directory to each existing email folder in the home directory. Refer to my article on links A user’s guide to links in the Linux filesystem for details on how to create them. Soft (symbolic) links also work, but I think that hard links are best for this type of situation.

This way both Thunderbird and Alpine are happy because they each get to use their own default locations for mail folders. I am happy because I did not have to spend a lot of time trying to hack those email clients. Well actually I did spend a lot of time doing that while researching this article, but now you won’t have to.

Now it is only necessary to remember to create a new hard link if I create a new folder using either client.

Some final thoughts

I find Alpine easy to use with its clean, simple interface and extensive features. Alpine is very fast because it does not attempt to download and display graphics. It does render HTML as plain text but it cannot be used to generate and send HTML; it is limited to plain text only. That is not a bad thing. Alpine – at least in the way I am using it – does not deal well with attachments; it usually does not know how to deal with ones that require a graphical application such as LibréOffice.

It also takes a little work to get this set up and to maintain it if new folders are needed. I find it well worth the effort because I can login from my laptop, my Android phone, or my Kindle using SSH and view my mail quickly and respond where necessary.

I do have some other alternatives to dealing with the problem of an ISP blocking outbound email on port 25. For example, my mobile phone works well as a wireless hotspot and AT&T, my mobile provider, does not block the outbound email so that works for me.

I will leave it to you to learn more about how to use Alpine. Alpine has a good man page and a nice built-in Help feature. Using those should get you started.