Tuesday, December 23, 2008

Rationalizing Your Email

A. Friend recently discovered, yet again, that the Evolution mail client doesn't like it when your Inbox grows bigger than 2 GB. I've never had this problem myself, but a family member once found that Netscape had a similar limit. So let's come up with a few rules about how to keep your email rational. Some of these are written for Thunderbird, my client of choice, but most other mailers have similar options. In no particular order:

  • Don't store your messages at all: Gmail currently has a 7.1GB limit on all messages. And if you use their IMAP function, you can view all your messages in your favorite email client (even Outlook). You can even put the mail in folders, because IMAP interprets Gmail's labels as a client's folders. Of course, you can only read your email when you are connected to the net, but you can read it from anywhere that has a modern Internet browser.

    Note: Don't use Gmail for anything you'd like to be able to delete before the subpoena arrives.
  • Use Filters: I use Thunderbird's filter mechanism to sort email before I read it. All email from news sources goes into a News folder, email from family or friends goes to a folder named for that person, emails from companies I ordered from exactly once goes to /dev/null, etc. Thunderbird then highlights the folder name and tells me how many emails I have unread in that folder (except /dev/null, for some reason), so I never miss anything.

    A.F. wants to post-filter his email: after it's read, put it in an appropriate folder. There's an option for that in the Thunderbird filtering system, as well.
  • Delete stuff: Each one of us has a friend that sends us an attached video, sound bite, or photo album each and every day. Look at them and delete. If something is so funny/moving/outrageous/sexy that just have to keep it, use the Save As feature to save the attachment in its native format, outside of your mailbox. Why? Well, in your mailbox the attachment is stored as 128 bits to the byte ASCII. In native format it will be stored using 256 bits to the byte. Do the math. You can also gzip the saved attachment much more easily than you can a single email in a folder. (Though emacs's RMAIL mode would read gzipped mail easily. Text only, unfortunately.)
  • If you think you simply must keep it in email: Ask yourself two questions: 1) Would I want to get this in an email next year?, and 2) Have I already sent this to 20+ people? If the answer to 1) is No, delete it now. If the answer to 2) is Yes, delete it — one of those 20 will forward it back to you within the week.
  • Compact your folders: Thunderbird, at least, doesn't actually delete an email message when you hit delete. It merely marks the email as deleted, and keeps it in your Inbox. That's handy if you accidentally delete something, but fatal to keeping the size of your Inbox down. Every once in a while use the Compact Folder option.
  • Periodically Reorganize: My work email box keeps getting larger and larger every day, since I get a lot of emails that resist proper filtering. So at the end of every year, I move all of my Inbox into a new folder, this year's will be called 2008 Mail. Do a similar thing for your Sent Mail folder. If you routinely send/receive more than 2 GB of email in a year, and can't bear to part with any of it, the problem's not in your mail client.

Those are my suggestions. Add yours below:

Monday, January 16, 2006

Command Line "mail" with SMTP

Back in the olden days*, when you wanted to send email from a Unix terminal, it went something like this:

$ mail  joeschmo@foobar.net
Subject:  Here's my email
Joe,

Mom said we should talk more often.  So I'm sending you this email.
Bye.
^D

And Joe would eventually get the email. (The ^D is Control-D, used to denote an end of file.) Now the nice thing about the old "mail" command is that it would accept anything from standard input. So if I wanted to send Joe a really long email I could put it in a big file, and pipe it into the mail command:

$ cat bigfile.txt | mail -s "Dear Joe" joeschmo@foobar.net

or

$ mail -s "Dear Joe" joeschmo@foobar.net < bigfile.txt

(The -s indicates that the next entry is the subject line of the email, the subject itself is in quotes to keep the command shell from thinking it's a bunch of options.)

This is fine so long as your local computer handles its own mail. However, these days home users mostly deal with ISPs, who have their own mail systems, which we usually access with an email client that understands the Simple Mail Transfer Protocol. These days, your email clients are usually graphical ones like Evolution, Thunderbird, Eudora, or Mozilla, but the all-you-can-eat text editor, Emacs, also can send mail via SMTP.

The program that can't send mail via SMTP is the old Unix "mail" command. It isn't the fault of "mail" itself, it's the fault of your Linux box. "mail" looks for a program called "sendmail", or its replacement, to send mail through the system. Now most sendmail-like programs assume that your computer, or one on your network, is your mailserver. They don't speak to your ISP via SMTP.

Why do I care? Well, a friend recently asked me if he could generate a file on his computer and send it to another friend without him having to do anything else. On a system with "mail" working, it's easy. Suppose the command "genbignovel" creates a large text file "pulitzer.txt". Then to write the novel and send it to Joe, who's on the Pulizter committee, I could create a small text file:

genbignovel
mail joeschmo@foobar.net < pulitzer.txt

which sends the file to Joe as soon as it's generated. If I'm using Evolution, Thunderbird, etc., then I have to send the file as an attachment, which means a bunch of mouse-clicks, at the very least.

So what we need is a replacement for sendmail which understands SMTP. A Google search reveals many, but the most popular one seems to be msmtp. I decided to try it out, so I downloaded the file, installed it using checkinstall, and tried to figure out how to set it up.

It's not too hard, though most people seem to use msmtp with mutt rather than mail. First, you need to create a file to tell msmtp which SMTP server you want to use, and the information needed to access that account. This is done through a file called ~/.msmtprc, i.e., a file named .msmtprc that lives in your home directory. Here's mine, with a few obvious changes:

account default
auto_from off
host smtp.gmail.com
from dubya@gmail.com
auth on
password xyzzymouse
user dubya@gmail.com
tls on

This obviously works on gmail, but you should be able to modify it for any SMTP server. You can look at the msmtp manual to see what everything means.

Now how do I get "mail" to use msmtp? Simplicity itself. mail uses a command file called ~/.mailrc. Create it, if you don't have one yourself, and add a line:

set sendmail=/usr/local/bin/msmtp

if you put msmtp in /usr/local/bin.

And now mail should work. It does from here, anyway.

Good God, how many posts of mine start with "back in the olden days?" Must remember that not everyone sent their first email in 1983.