Feb 28, 2009

Be a registered Linux user and Ubuntu user!

Did you notice the "Registered Linux user 485011" pic on the right? What are your waiting for? Register your machine NOW!

http://counter.li.org/

Also, register as a Ubuntu user if you are using Ubuntu here, and get a cool tag:

http://ubuntucounter.geekosophical.net/

Look at the names of Linux servers of ECE@UTexas

ryu.ece.utexas.edu
ehonda.ece.utexas.edu
blanka.ece.utexas.edu
guile.ece.utexas.edu
ken.ece.utexas.edu
chunli.ece.utexas.edu
zangief.ece.utexas.edu
dhalsim.ece.utexas.edu
balrog.ece.utexas.edu
vega.ece.utexas.edu
sagat.ece.utexas.edu
mbison.ece.utexas.edu
cammy.ece.utexas.edu
deejay.ece.utexas.edu
thawk.ece.utexas.edu
feilong.ece.utexas.edu
akuma.ece.utexas.edu
gouki.ece.utexas.edu

Feb 27, 2009

Multiple accounts in Mutt

Q: How to set up multiple accounts in Mutt?
A: Three steps:
  1. Set up multiple accounts in fetchmail to receive emails from different accounts;
  2. set up multiple accounts in msmtp to send email with multiple accounts;
  3. set up multiple accounts control in mutt.
The first step is explained in my Mutt tutorial post. I assume now you can receive different emails from This post will focus on how to control send emails with different accounts.

First of, you need to have multiple accounts setting in your .msmtprc file. For example, here I have two Gmail accounts setting:

account gmail
host smtp.gmail.com
port 587
from goodguy@gmail.com
tls on
tls_starttls on
tls_trust_file /home/usrname/mail/certs/Thawte_Premium_Server_CA.pem
auth on
user goodguy
password 1234567

account gmail1
host smtp.gmail.com
port 587
from badguy@gmail.com
tls on
tls_starttls on
tls_trust_file /home/usrname/mail/certs/Thawte_Premium_Server_CA.pem
auth on
user badguy
password abcdefg

account default: gmail

Default account is the first account, as specified in the config file. Now what you need to do is to control when to send email with first account, and when with the second account.

You need add the following lines to your .muttrc file to enable multiple accounts support.

Few things to explain. There is a "from" environment in your .muttrc file. If the default value is goodguy@gmail.com, your default account when composing email or replying email sent to accounts other than the emails specified in "alternate" emails is goodguy@gmail.com.

The ugly status set in the macro is to help you know what the "from" environment is.

set envelope_from ="yes"

set reverse_name=yes

alternates "goodguy@gmail.com|badguy@gmail.com"

macro index \e1 ":set signature=~/.signature_private\n:\
set from=goodguy@gmail.com\n:set status_format=\"-%r-Gmail: %f \
[Msgs:%?M?%M/?%m%?n? New:%n?%?o? Old:%o?%?d? Del:%d?%?F? \
Flag:%F?%?t? Tag:%t?%?p? Post:%p?%?b? Inc:%b?%?l? %l?]---(%s/%S)-%>-(%P)---\"\n"\
"Switch to Gmail"

macro index \e2 ":set signature=~/.signature_fake\n:\
set from=badguy@gmail.com\n:set realname=Jason\n:set status_format=\"-%r-Gmail2: %f \
[Msgs:%?M?%M/?%m%?n? New:%n?%?o? Old:%o?%?d? Del:%d?%?F? \
Flag:%F?%?t? Tag:%t?%?p? Post:%p?%?b? Inc:%b?%?l? %l?]---(%s/%S)-%>-(%P)---\"\n"\
"Switch to Gmail2"

The first three lines are to enable email matching during reply. That is, when you are replying emails sent to goodguy@gmail.com, the "From:" header is automatically set as goodguy@gmail.com, so that you don't need to set which account to use manually before reply. Note that this will not change the "from" environment, so when you compose new mail, the "From:" header will be the default "from" environment in .muttrc file, or others if you have manually changed the "from" environment as shown below.

If you need to compose a new email, you can choose which account to use by pressing ALT+1 or ALT+2, which will set the "from" environment to goodguy@gmail.com and badguy@gmail.com respectively.

Once you specified your "From:" header, msmtp will compare the header with "from" line in .msmtprc file, to find account with that email address to send the email. If msmtp can't find one, it will send email with default account in .msmtprc file.

OK, Done.

How to have a three columns template

Here's a very straight forward post on editing minima blogspot template to have three columns, like mine now.

Link

How to add a "Digg" button to your blogspot posts?

This is a pretty easy task, follow these steps:

  1. Go to "Layout" - "Edit HTML"
  2. Backup your template
  3. Click the box "Expand Widget Templates"
  4. Find "<data:post.body/>" in the template
  5. Add following lines BEFORE "<data:post.body/>"

<div style='float:right; margin-left:10px;'>
<script type='text/javascript'>
digg_url=&quot;<data:post.url/>&quot;;
</script>
<script src='http://digg.com/tools/diggthis.js' type='text/javascript'/>
</div>

How to archive your emails once a while?

If you are using Mutt, your mailbox files would grow larger and larger until it takes several seconds to open it in Mutt. One would say: gee, why do you keep old emails? Well, why not? I believe there should be enough space to store the old emails in hard drive nowadays. So here's the question: how do we save old emails?

Here's what we need to do:
  1. Don't delete emails, archive them into a specific mailbox, say, "archive" when hitting in Mutt. (By default, it is "d")
  2. Archive this mailbox into .tar file, and organize them in your mail directory so you can read them when you need to
  3. Delete the old "archive" mailbox file, and create a new and empty "archive" mailbox file.
  4. Do 1~3 every ten days.
OK, let's get started.

1 Save emails

This is simply redefine the "d" key, by default the delete key, in Mutt. Write the following in your .muttrc

macro index,pager d 's=archive'

Now when you hit "d", the email is not deleted, but saved to the archive mailbox.

2 Archive emails and delete old mailbox file

Here I assume you are using mbox mailboxes. Since we need to do this every ten days, a good choice is to write a script and let the system run this script every ten days. Here's the script I wrote.

#!/bin/sh

#set archive directory
basedir=/home/usrname/mail/archive/
#define archive directory suffix
suffix=$(date +%Y%m%d)
#define archive directory name
desdir=$basedir$suffix
cd /home/usrname/mail/
#create archive directory
mkdir $desdir
tar czf $desdir/archive.tar.gz archive
#remove old mailbox
rm archive
#create a new archive mailbox
touch archive
echo Email archive-$suffix successfully created #echo a success message


Save the script in your home directory, and change the mode of the script by running

chmod 700 email-archive


Then try the script in your home directory.

./email-archive


3 Configure crontab


Cron is a unix, solaris utility that allows tasks to be automatically run in the background at regular intervals by the cron daemon. These tasks are often termed as cron jobs in unix, solaris. To set the script to run every ten days, run the following command to edit cron jobs.

crontab -e

By default, it will get you into a vim editor. If you don't know how to use vim, follow the instruction at the end of this post.

In the editor, add the following line.

30 21 1,10,20 * * $HOME/email-archive


Run the following command to see if the cron job is correctly set.

crontab -l


Done!

Vim basics


When vim is started, you are not in the edit mode. Move cursor by hitting "j, k, h, l", and hit "i" at where you want to edit. You can see the INSERT not at the bottom. After done editing, hit ESC to quit edit mode. Then hit shift-z twice to save and quit.

Mutt tutorial | Mutt Configuration

Thank Andrew, Mark Stosberg for their insightful Mutt configuration web page.

Mutt is a text based email client. It doesn't have fancy interfaces like outlook, thunderbird. But indeed it is the most handy and configurable email client I've ever used. I've been using Mutt for a month, which is a tough month because I have to configure this and that until I feel comfortable using it.

Unlike other email clients, to use Mutt, you have to install at least two programs other than Mutt. One is for getting emails from server, another is for sending emails. In this tutorial, I use fetchmail to get email and msmtp to send mail. I also will introduce procmail, which is used to sort your emails into different mailboxes, which is extremely efficient if you have a large number of emails to read.

OK, let's get started.

1 Install

First of, you need to install all of the programs. In Debian based Linux OS, you just need to type the following command in a terminal

sudo apt-get install mutt fetchmail msmtp procmail


At this point, you'll see nothing when running mutt. That's because nothing has been set up, so mutt doesn't know where the mailboxes are. Therefore, our first goal is to receive the emails and save them to your computers. (I'm not a big fan of saving emails on the server, so I prefer downloading them to my hard drives and archiving old emails once a while)

After install, you need to set your email file in your system, and any incoming email are saved there. Let's say it's in the /home/username/mail/inbox file. To do this, simply create the folder in your home directory and add the following line in your .bashrc file.

MAIL=/home/username/mail/inbox && export MAIL


2 Receive Emails


2.1 fetchmail


Fetchmail can fetch your emails from server via POP3 and IMAP protocols, and It's pretty easy to set up.

First, create a file named .fetchmailrc in your home directory, and change the permission of this file by running following command (because you probably will write your password in this file).

chmod 700 .fetchmailrc


Then add the following lines to this file.

poll pop.gmail.com with proto POP3
user 'a@gmail.com' there with password 'aaa' is 'usrname' here options stripcr ssl sslcertck sslcertpath '/home/usrname/mail/certs/' keep
mda '/usr/bin/procmail -d %T'

poll pop.gmail.com with proto POP3
user 'b@gmail.com' there with password 'bbb' is 'usrname' here options stripcr ssl sslcertck sslcertpath '/home/usrname/mail/certs/' keep
mda '/usr/bin/procmail -d %T'

Change "usrname" to your Linux username. Note that I included ssl certificate check. The certificate file, as shown above, in located in your /home/username/mail/certs/ directory.

The certificates you need if you are setting up Gmail are Equifax_Secure_CA.pem and Thawte_Premium_Server_CA.pem. create the certificate files in your certs/ folder:

cd ~/mail/certs
touch Thawte_Premium_Server_CA.pem
touch Equifax_Secure_CA.pem

Then add these to your Thawte_Premium_Server_CA.pem:

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mOeUJXRmm/kEd5jhW6Y7qj/WsjTVbJmcVfewCHrPSqnI0kB
BIZCe/zuf6IWUrVnZ9NA2zsmWLIodz2uFHdh1voqZiegDfqnc1zqcPGUIWVEX/r87yloqaKHee95
70+sB3c4
-----END CERTIFICATE-----

Then let the system know where the certificates are by running

$ c_rehash $HOME/mail/certs/


2.2 procmail


Since this tutorial is getting longer and longer, I'll explain procmail in a separate post. For now, all your mail will go to your $HOME/mail/inbox file.

3 Send mail


Create .msmtprc file in your home directory. Add following lines to this file.

account gmail
host smtp.gmail.com
port 587
from a@gmail.com
tls on
tls_starttls on
tls_trust_file /home/usrname/mail/certs/Thawte_Premium_Server_CA.pem
auth on
user a
password aaa

account gmail1
host smtp.gmail.com
port 587
from b@gmail.com
tls on
tls_starttls on
tls_trust_file /home/usrname/mail/certs/Thawte_Premium_Server_CA.pem
auth on
user b
password bbb

account default: gmail

Then change the permission as well:

chmod 700 $HOME/.msmtp


4 Configure Mutt


Create a file .muttrc in your home directory. Then add following to this file. A complete configuration file can be downloaded here

#======================================================#
# Default setting

set realname = "Your Name"
set from = "a@gmail.com" #Default account
set status_format="-%r-Gmail: %f [Msgs:%?M?%M/?%m%?n? New:%n?%?o? Old:%o?%?d?\
Del:%d?%?F? Flag:%F?%?t? Tag:%t?%?p? Post:%p?%?b? Inc:%b?%?l? %l?]---(%s/%S)-%>-(%P)---"

set use_from
set envelope_from ="yes"
set nomark_old
#set signature="~/.signature"

set sendmail="/usr/bin/msmtp"

set spoolfile = ~/mail/inbox

#=====================================================#
# Folders

set folder="$HOME/mail" # Local mailboxes stored here
set postponed="+postponed" # Where to store draft messages
set mbox_type=mbox # Mailbox type
set record="+/sent/sent-mail-`date +%Y-%m`"

#======================================================#
mailboxes ! =work =play

set sort_browser=size
#======================================================#
#Headers

ignore *
unignore Date: From: User-Agent: X-Mailer X-Operating-System To: \
Cc: Reply-To: Subject: Mail-Followup-To:
hdr_order From: Date: To: Cc: Reply-To: User-Agent: X-Mailer X-Operating-System Subject:

#======================================================#
# Editor

set editor="vim -c 'set tw=70 et' '+/^$' "
set edit_headers=yes # See the headers when editing

#======================================================#
# Aliases

set alias_file = ~/mail/.mutt_aliases # In their own file
source ~/mail/.mutt_aliases # Source them
set sort_alias=alias # Sort alphabetically

#======================================================#
# Colours: defaults are a little bleak so experiment!

source ~/mail/.colors # In their own file

#======================================================#
# Lists

subscribe mutt-users
set followup_to=yes # Sets 'Mail-Followup-To' header
set honor_followup_to=yes
fcc-hook mutt =mutt #See own posts

#======================================================#
# Compose

set markers # mark wrapped lines of text in the pager with a +
set smart_wrap # Don't wrap mid-word
set pager_context=5 # Retain 5 lines of previous page when scrolling.
set status_on_top # Status bar on top.
push # Shows mutt version at startup

set delete=yes
set sendmail_wait=-1
set forward_format="Fwd: %s"
set query_command="lbdbq '%s'"
set include # include original message
set fast_reply # No waiting after send
set wait_key=yes
set abort_nosubject=no
set abort_unmodified=no

#======================================================#
# Macros & Bindings

macro index,pager y ? "See mailbox list"
macro index,pager I ' fetchmail -v' "Fetchmail"
macro index,pager n '?'\
"Switch to next mailbox"

bind index,pager v next-unread-mailbox
bind index,pager V view-attachments
bind index ^N next-page
macro index d 's=archive'
macro index A 's=important'
bind index,pager ^D delete-message

bind browser v check-new
bind browser i exit
bind browser select-entry
bind browser view-file

bind index B bounce-message

#======================================================#
# Set multiple accounts

set reverse_name=yes

alternates "aaa@gmail.com|bbb@gmail.com"

macro index \e1 ":set signature=~/.signature_private\n:\
set from=aaa@gmail.com\n:set status_format=\"-%r-Gmail: %f \
[Msgs:%?M?%M/?%m%?n? New:%n?%?o? Old:%o?%?d? Del:%d?%?F? \
Flag:%F?%?t? Tag:%t?%?p? Post:%p?%?b? Inc:%b?%?l? %l?]---(%s/%S)-%>-(%P)---\"\n"\
"Switch to Gmail"

macro index \e2 ":set signature=~/.signature_fake\n:\
set from=bbb@gmail.com\n:set realname=Jason\n:set status_format=\"-%r-Gmail2: %f \
[Msgs:%?M?%M/?%m%?n? New:%n?%?o? Old:%o?%?d? Del:%d?%?F? \
Flag:%F?%?t? Tag:%t?%?p? Post:%p?%?b? Inc:%b?%?l? %l?]---(%s/%S)-%>-(%P)---\"\n"\
"Switch to Gmail2"

#======================================================#
# Print

set print = yes
set print_command="muttprint"


#======================================================#
# Html autoview
# Note: turn off autoview if you have Chinese google
# mailgroup/maillist

#auto_view text/html

#======================================================#
# Hook config

send-hook aaa@163.com$ 'my_hdr From: Good Guy '
send-hook aaa@163.com$ 'set signature="~/.signature_private"'

#======================================================#
# Misc

unset confirmappend # No confirmation after save



I suggest you read this line to line. The configuration is pretty self-explanatory. Note that I put my mutt color config. in another file and sourced it in .muttrc file. Also note that I have set up lots of custom-keybinding, you can change that if you want - Mutt is pretty good at custom configuration. The action defined after every keybinding set up can be found in Mutt it self. Just hit "?", you can see all the key bindings.

Basically, the most used keys are:
  • j: move to next unread email
  • k move to previous unread email
  • SPACE read current email
I'll write tutorials on color, procmail, and multiple accounts setup later.

5 Acknowledgment and useful links


Using Mutt with Gmail
The Mutt Cheatsheet
Learning Mutt
Mark's Mutt Fan and Tip page

6 Related Posts

Multiple accounts in Mutt

Feb 11, 2009

How do I to disable the mail alert send by crontab?

Q. How do I to disable the mail alert send by crontab? When my job is executed and the jobs cannot run normally it will sent an email to root. Why do I receive e-mails to my root account from cron? How can I prevent this?

A. crontab command is use to maintain crontab files for individual users.

By default the output of a command or a script (if any produced), will be email to your local email account. To stop receiving email output from crontab you need to append following string:

Cron Job Prevent the sending of errors and output

To prevent the sending of errors and output, add any one of the following at the end of the line for each cron job to redirect output to /dev/null.
>/dev/null 2>&1.
OR
&> /dev/null

Feb 9, 2009

Finally figured out why my UT webmail can't receive email

That's because I set up an forwarding email in the system.
And the server will not keep the email after forwarding it, kinda like what procmail does.

Anyway, now I can use a simple username university email. xxxxx@mail.utexas.edu as my work email, and gmail as my personal email.

Great!

Feb 8, 2009

Road to Linux 2009

Once upon a time, I installed Ubuntu-I-forgot-the-version on my PC in college, with dual boot of course. It was interesting, although Linux desktop wasn't as good as it is now. That Linux installation ended up ... system crash.

The laptop I am using now was bought in Oct 2008. Lenovo Thinkpad T61, T9300, 2G, 100G. I choose Windows Vista Business when I bought it - pretty expensive. Then I got sick of Windows, and thought, gee, why not install an Ubuntu on it. There started my road to Linux, the only OS on my laptop now.

Long story short, here is the time table.

Dec 2008, I installed Ubuntu 8.04 LTS on my girlfriend's old laptop Thinkpad R51, through wubi installation.

Jan 2009, I installed same distro on my T61, with dual boot, and everything worked great.

Jan 2009, Bye Windows. My T61 is powered by Ubuntu, only.

Installing Ubuntu was pretty easy, and there are tons of threads of discussion on Ubuntu on internet. I burned the 8.04LTS to cd, and took 20ish minutes to get it done. The only thing needs to be pointed out is that I didn't use the default partition option. My partition is / 20G, /swap 2G, and /home the rest of my 100G hard drive.


Welcome to Non-geek's
Linux Handbook!

or if you will, Linux Cookbook.

Read my READY-TO-USE
RECIPE-LIKE
tutorials on Linux applications~

Subscribe if you are willing to follow.

If you find the post useful, please click the donate button on the upper right corner. Any amount is useful.