Posted inExperience / Information Technology

How to Set Up Mutt to Work With JustHost.com Email

Every now and then you are going to need to send email from the command line. In the world of OpenVMS we did it from batch jobs all of the time. Yes, there were abort routines which would notify all operators currently logged in and who had typed REPLY/ENABLE at their terminal, but, you still sent email just in case. OpenVMS had a robust email system long before we had an Internet, indeed, long before personal computers.

Yes, even you Web only children will find yourselves in need of sending email from a back end process. The simplest way is via a batch job which some people in that world call “shell scripts.” In my case I was testing the blog-via-email plug-in on this site. You see, the HTML editor in Thunderbird was and is nowhere near ready to create blog posts. Could not get it formatted correctly with images. This meant editing an HTML file and sending from command line.

I have many editors. Most of these editors could have easily let me hack at the code level creating a pure HTML document, but I wanted to test one which was a bit more WYSIWYG (What You See Is What You Get) so I pulled down the latest version of Blue Griffon. I must say I was impressed. This editor has come a long way from its humble (and extremely buggy) nVu beginnings. It still has quite a ways to go, but it is getting there.

Some things I noticed:

  1. You can select a bunch of stuff on the screen then click a toolbar button to “wrap” the selected stuff inside of a list of HTML tags. It’s a short list though. It includes span but does not include div. I needed div so I had to drop to code to wedge it in. I could insert a div tag via a menu option, but, if you are in the GUI display you can’t actually get inside the div tag to add content which kind of defeats the whole purpose.
  2. There are many formatting buttons on the left. You can choose left, right, center and full justification. They were missing a button for style=”float: left;” which is what you need to put an image on the left side of the page while allowing text to be on the right, assuming you don’t wish to deal with all of the problems a table creates.

I’m doing this with LinuxLite, but it is a YABU (Yet Another uBUntu) based on 16.04.

roland@roland-HP-Compaq-8100-Elite-SFF-PC:~$ lsb_release -a
No LSB modules are available.
Distributor ID:    Ubuntu
Description:    Linux Lite 3.2
Release:    16.04
Codename:    xenial

I installed mutt from the package manager and it installed some dependencies. During the install a dialog with combo box will popup asking you to configure a few postfix settings. Just remember to choose Internet, which is the default. In short, take the defaults. Once installation is complete open a terminal and edit the .bashrc file found in your $HOME. Add this line somewhere it will always be executed.

export MAIL=/var/mail/<user_name>

Be sure to replace <user_name> with your own user name. Save and exit, then we need to tweak a few things because mutt and postfix are still keeping the Linux traditions of “dark art – expert friendly” alive.

NOTE: I use an IMAP server for email, not POP3. I have no idea what one does for POP3 if you are still using such an email service. Most people have moved to IMAP because it allows them to access email from any device while POP3 pulls it down to one machine and that is where it lives.

Open a terminal window and edit .muttrc. You should have to create it.

set realname = "My Name"
set from = "<your_email>"
set use_from = yes
set envelope_from = yes

set smtp_url = "smtps://<your_email>@just49.justhost.com:465/"
set smtp_pass = "<your_password>"
set imap_user = "<your_email>"
set imap_pass = "<your_password>"
set folder = "imaps://just49.justhost.com:993"
set spoolfile = "+INBOX"
set ssl_force_tls = yes

I will assume you figured out things in <> need your values.

Once you save this file reboot. Open a terminal to type the following commands.

:~$ echo $MAIL
/var/mail/roland
:~$ sudo touch $MAIL
[sudo] password for roland: 
:~$ sudo chmod 660 $MAIL
:~$ sudo chown `whoami`:mail $MAIL

You can test everything by typing mutt and watch it start pulling down your mail, then you can hit ‘q’ to quit. If you happen to have an html or text file laying around you are ready to send your first batch email.

mutt -s "testing mutt" someone@desitnation.com < "Farmer Fred and the IRS.html"

The -s identifies the subject and the message will consist of the contents from the other side of the <. Yes, there are many things one can do with mutt, it is a full text email client you can use in the terminal. Yes, I could have spent even more time and got postfix to work with the regular linux mail command, but, I had no idea what the dark art configuration file was called or how to change the settings in it. There seem to be dozens of .muttrc files littering the Internet and the variables are easily named. The only difficult part was finding this link with the correct port numbers and server names.

If you want the email to actually go out as HTML ad:

-e "set content_type=text/html"

after setting the subject.

Roland Hughes started his IT career in the early 1980s. He quickly became a consultant and president of Logikal Solutions, a software consulting firm specializing in OpenVMS application and C++/Qt touchscreen/embedded Linux development. Early in his career he became involved in what is now called cross platform development. Given the dearth of useful books on the subject he ventured into the world of professional author in 1995 writing the first of the "Zinc It!" book series for John Gordon Burke Publisher, Inc.

A decade later he released a massive (nearly 800 pages) tome "The Minimum You Need to Know to Be an OpenVMS Application Developer" which tried to encapsulate the essential skills gained over what was nearly a 20 year career at that point. From there "The Minimum You Need to Know" book series was born.

Three years later he wrote his first novel "Infinite Exposure" which got much notice from people involved in the banking and financial security worlds. Some of the attacks predicted in that book have since come to pass. While it was not originally intended to be a trilogy, it became the first book of "The Earth That Was" trilogy:
Infinite Exposure
Lesedi - The Greatest Lie Ever Told
John Smith - Last Known Survivor of the Microsoft Wars

When he is not consulting Roland Hughes posts about technology and sometimes politics on his blog. He also has regularly scheduled Sunday posts appearing on the Interesting Authors blog.