Using Secure Mutt Connections with IMAPS

January 31, 2009 Mail Client

Getting Started with mutt

On an Ubuntu 8.10 Desktop you will need to install both mutt and sSMTP.

sudo apt-get install mutt
sudo apt-get install ssmtp

Once you have SSMTP and mutt installed you can test your email by creating two users and sending mail from one at the command line to the other user.  Here mail is sent to the user tom on the local machine.

echo “Test” | mutt -s Hello tom

The -s is the option that creates the Subject line.

Sending Email
Now you want to be able to send email to the Internet so you will want to edit your /etc/ssmtp/ssmtp.conf file.   It is important that you understand where your mail server is that you will send mail to, this is the mailhub setting.  Mail servers must have a Fully Qualified Domain Name so you will need something like mail.example.com.  Note, this setting will allow you to send email to the mail server of your ISP or your own mail server.  However, your mail server must be set up to allow you to send mail to it, if not you will have difficulty as Spam filters typically should not allow mail from anything but a properly configured mail server.

#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=postmaster

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=mail.example.com

# Where will the mail seem to come from?
rewriteDomain=example.com

# The full hostname
hostname=dg

You can check your version and the options that are compiled inot your mutt with this command.
mutt -v
Mutt 1.5.18 (2008-05-17)
Copyright (C) 1996-2008 Michael R. Elkins and others.
Mutt comes with ABSOLUTELY NO WARRANTY; for details type `mutt -vv’.
Mutt is free software, and you are welcome to redistribute it
under certain conditions; type `mutt -vv’ for details.

System: Linux 2.6.27-9-generic (i686)
ncurses: ncurses 5.6.20071124 (compiled with 5.6)
libidn: 1.8 (compiled with 1.8)
hcache backend: GDBM version 1.8.3. 10/15/2002 (built Jun 15 2006 21:19:27)
Compile options:
-DOMAIN
+DEBUG
-HOMESPOOL  +USE_SETGID  +USE_DOTLOCK  +DL_STANDALONE
+USE_FCNTL  -USE_FLOCK
+USE_POP  +USE_IMAP  +USE_SMTP  +USE_GSS  -USE_SSL_OPENSSL  +USE_SSL_GNUTLS  +USE_SASL  +HAVE_GETADDRINFO
+HAVE_REGCOMP  -USE_GNU_REGEX
+HAVE_COLOR  +HAVE_START_COLOR  +HAVE_TYPEAHEAD  +HAVE_BKGDSET
+HAVE_CURS_SET  +HAVE_META  +HAVE_RESIZETERM
+CRYPT_BACKEND_CLASSIC_PGP  +CRYPT_BACKEND_CLASSIC_SMIME  -CRYPT_BACKEND_GPGME
-EXACT_ADDRESS  -SUN_ATTACHMENT
+ENABLE_NLS  -LOCALES_HACK  +COMPRESSED  +HAVE_WC_FUNCS  +HAVE_LANGINFO_CODESET  +HAVE_LANGINFO_YESEXPR
+HAVE_ICONV  -ICONV_NONTRANS  +HAVE_LIBIDN  +HAVE_GETSID  +USE_HCACHE
-ISPELL
SENDMAIL=”/usr/sbin/sendmail”
MAILPATH=”/var/mail”
PKGDATADIR=”/usr/share/mutt”
SYSCONFDIR=”/etc”
EXECSHELL=”/bin/sh”
MIXMASTER=”mixmaster”
To contact the developers, please mail to <mutt-dev@mutt.org>.
To report a bug, please visit http://bugs.mutt.org/.

patch-1.5.13.cd.ifdef.2
patch-1.5.13.cd.purge_message.3.4
patch-1.5.13.nt+ab.xtitles.4
patch-1.5.4.vk.pgp_verbose_mime
patch-1.5.6.dw.maildir-mtime.1
patch-1.5.8.hr.sensible_browser_position.3

Mutt Basics
Once it is all installed you can open mutt with:
mutt

This is what you will get with mutt.  Each key is defined for you at the top of the window. You may quit mutt with “q”.  Delete “d” or undelete “u” mail are options you need to get used to as this is how you will clean out your mail box.  In fact, if you look at the bottom of the example you see the directory for the mail, /var/mail/user_name.  If you want to save mail use the “s”, reply with “r”.

q:Quit  d:Del  u:Undel  s:Save  m:Mail  r:Reply  g:Group  ?:Help

—Mutt: /var/mail/mike [Msgs:0]—(threads/date)————————————(all)—

The “m” option will create a new email.  It will open the “To:” and you may then enter the email address you want to send to.

To: mike@example.com

When you hit enter it will bring up the subject line that you can fill in.

Subject: test email from mutt

Hit enter again and nano opens to allow you to edit the email you want to send.

Nano is an alternative text editor.  The  key sequences in nano are entered using the keyboard making nano  a “modeless” editor, unlike vim. With the exception of Control and Meta key sequences, all the keys will enter text into the file being edited.  You do not have to switch modes at all.  In addition, nano provides some text aids.

Opening Screen
When you issue the nano command without any options the program opens as you see below with basic command available using Ctrl+Letter(the ^ symbol represents the Ctrl key).

GNU nano 2.0.7                New Buffer

^G Get Help    ^O WriteOut    ^R Read File   ^Y Prev Page   ^K Cut Text      ^C Cur Pos
^X Exit            ^J Justify          ^W Where Is   ^V Next Page  ^U UnCut Text  ^T To Spell

Basic Commands
^G    get help
Main nano help text
The nano editor is designed to emulate the functionality and ease-of-use of  the UW Pico text editor.  There are four main sections of the editor.  The top  line shows the program version, the current filename being edited, and whether  or not the file has been modified.  Next is the main editor window showing the  file being edited.  The status line is the third line from the bottom and  shows important messages.  The bottom two lines show the most commonly used  shortcuts in the editor.

^O     write the file
If you write text you may write to a file with this command.
File Name to Write: newfile

^R    read a file
When you would like to open a file use this command and then supply the path or if it is in your path the filename.
File to insert [from ./] : /home/mike/newfile

^Y    previous page
^K    cut text
^C    current position
This will provide information about the current position.  In this example of writing an email, you will see the status line at the bottom.

GNU nano 2.0.7             File: /tmp/mutt-dg-1000-12143-0                       Modified

When you use nano you can begin typing immediately as there are no modes like in vi.
This certainly makes it easier to use as a text editor as it eliminates one layer of
complexity.

[ line 5/6 (83%), col 1/1 (100%), char 186/187 (99%) ]
^G Get Help    ^O WriteOut    ^R Read File   ^Y Prev Page   ^K Cut Text    ^C Cur Pos
^X Exit        ^J Justify     ^W Where Is    ^V Next Page   ^U UnCut Text  ^T To Spell

^X    exit
^J    justify

^W    where is
If you need to search an email you can use this command. As soon as you select ^W you will receive a search field to look for the text string you want.  It will take you to the first example of that text string.

^V    next page, scroll through pages
^U    uncut text or paste
^T    spell check

GNU nano 2.0.7             File: /tmp/mutt-dg-1000-12143-0                       Modified

When you use nano you can begin typing immediatley as there are no modes like in vi.
This certainly makes it easier to use as a text editor as it eliminates one layer of
complexity.

^G Get Help    ^O WriteOut    ^R Read File   ^Y Prev Page   ^K Cut Text    ^C Cur Pos
^X Exit        ^J Justify     ^W Where Is    ^V Next Page   ^U UnCut Text  ^T To Spell

Once you are done with your email use ^O and you will see the option to write the email:

File Name to Write: /tmp/mutt-dg-1000-12143-0
^G Get Help            ^T To Files            M-M Mac Format         M-P Prepend
^C Cancel              M-D DOS Format         M-A Append             M-B Backup File

Hit enter and it will be written.

Now use ^X to exit and then select “y” to send immediately and you should see this message at the bottom of the screen.

—Mutt: /var/mail/mike [Msgs:0]—(threads/date)————————————(all)—
Mail sent.

Until you send the email you will see your email in the /tmp directory waiting to be sent.

y:Send  q:Abort  t:To  c:CC  s:Subj  a:Attach file  d:Descrip  ?:Help
From: mike <mike@dg>
To: mike@example.com
Cc:
Bcc:
Subject: test email
Reply-To:
Fcc: ~/sent
Mix: <no chain defined>
Security: Clear

– Attachments
- I     1 /tmp/mutt-dg-1000-12143-4                       [text/plain, 7bit, us-ascii, 0.1K]

If you need help with mutt you can use the “?” and it will show you a list of options.

i:Exit  -:PrevPg  <Space>:NextPg ?:Help
^B          M <enter-command> s… call urlview to extract URLs out of a message
^D          toggle-disposition     toggle disposition between inline/attachment
^E          edit-encoding          edit attachment transfer-encoding
^F          forget-passphrase      wipe passphrase(s) from memory
<Return>    view-attach            view attachment using mailcap entry if
+                                  necessary
^T          edit-type              edit attachment content type
^Xe         edit-file              edit the file to be attached
<Esc>f      edit-from              edit the from field
<Esc>k      attach-key             attach a PGP public key
A           attach-message         attach message(s) to this message
C           copy-file              save message/attachment to a file
D           detach-file            delete the current entry
E           edit-headers           edit the message with headers
F           filter-entry           filter attachment through a shell command
G           get-attachment         get a temporary copy of an attachment
M           mix                    send the message through a mixmaster remailer
+                                  chain
P           postpone-message       save this message to send later
R           rename-file            rename/move an attached file
S           smime-menu             show S/MIME options
Help for compose

Receiving Mail

Here you can see an new email (email #3) has arrived.  By typing the number “3” you are able to open that specific email.

q:Quit  d:Del  u:Undel  s:Save  m:Mail  r:Reply  g:Group  ?:Help
1     Jan 31 Mike            (1.1K) Re: test from bs
2     Jan 31 mike            (1.0K) test email
3 N   Jan 31 mike            (1.1K) └─>

Jump to message: 3

Also notice the arrow that indicates that the email is a response to a previous email.

Delete Email
When you are working with mutt you will want to delete mail that you no loner want.  You can do that by selecting the email in the list and choosing “d” which will place a capital “D” in the front of the email and it will be removed

Using Secure Mutt Connections with IMAPS
You will need to set up your mail server so that it will be able to use IMAPS on port 993.   This means that your connection is secured with TLS, Transport Layer Security, the improvement on SSL. Once you have your server set up then you can use mutt to make a secure connection and send email as well.  In order to connect mutt just use this command to connect and start muttt.
mutt -f imaps://mike@mail.example.com

That will request the password for you account and then provide you access to the mail on the server.

If your email account is as a virtual user on the mail server.  For example, if the mail server was mail.example.com and that mail server was providing the domain mail for you at mycompany.com you would have to connect using this method:

mutt -f imaps://mike%40mycompany.com@mail.example.com

You are connecting with IMAP but you are listing your virtual user account, mike@mycompany.com as with %40 to represent the @ symbol of the virtual account.  You cannot do this:

mutt -f imaps://mike@mycompany.com@mail.example.com

Once you have that set up you should be able to login and send email.

Tags: , ,

Comments are closed.