Using nbsmtp with mutt

This used to be part of my mutt page, but since I now use ssmtp I put this page up for those who do prefer nbsmtp.

Mutt is a very lightweight email and news client--whereas Pine sets the smtp server for you, Mutt relies upon configuring sendmail, postfix, or something else. Depending upon your distribution, the easiest way, for the home user may be to download a little utility called nbsmtp. (For nobrainer smtp

At time of writing, nbsmtp is available here. It seems to move from time to time, so if that link is no good, just do a search on google for nbsmtp

Download it somewhere and as root, or with root privilege

su

Type in root's password
Go to where you downloaded the file

tar -zxvf nbsmtp-x.x.tar.gz

(obviously, substitute the x.x with the version number)

make linux

(note there's no cd'ing to a new file)
You'll see a few files in there, including one called nbsmtp with no suffix. Move that to a common path, such as /usr/bin or /usr/local/bin.

mv nbsmtp /usr/bin/
chmod 755 /usr/bin/nbsmtp

Now anyone can use the program.

The above is for Linux--in FreeBSD one can simply install nbsmtp through the ports collection--just cd to it in /usr/ports/net/mail/nbsmtp and type

make install

It will put the executable file in /usr/local/bin.

To use it with mutt, edit your .muttrc
If your ISP is called isp.com, your email address is john@isp.com and isp.com's smtp server is smtp.isp.com, you would add the following

set sendmail="/usr/local/bin/nbsmtp -d isp.com -f john@isp.com -h smtp.isp.com"

/usr/local/bin/nbsmtp is telling it our smtp client. (That's from a FreeBSD configuration. FreeBSD puts most things in /usr/local/bin--if you had it in /usr/bin/ then of course it would read /usr/bin/nbsmtp etc)

We added the flags -d for domain -f for from and -h for host. John's domain is isp.com. His email should appear as coming from john@isp.com and the host refers to his ISP's smtp server which is smtp.isp.com

Using multiple accounts

Let's say that our sample user john has a second isp. In this case, his user name is also john, with a password of 1234. The pop server is pop.isp1.com and the smtp server is smtp.isp1.com. His new email address there is john@isp1.com John has one mailing list, mail@mailist.com to which he has subscribed with the new acount.

To send a message to mail@mailist.com, he has to use isp1.com's smtp server as well as have his header show that it's from john@isp1.com rather than isp.com.

He will have to put a couple of send-hook lines in his .muttrc--this will take action if we are sending to mail@mailist.com. Add the following

send-hook "mail@mailist.com" "my_hdr From: John <john@isp1.com>
send-hook "mail@mailist.com" 'set sendmail="/usr/bin/nbsmtp -d isp1.com -f john@isp1.com -h smtp.isp1.com"'

A friend who found that my .muttrc didn't work for him, mentioned doing it as shown below, escaping the dots with backslashes.

send-hook "mail@mailist\\.com" "my_hdr From: john@isp1.com"

The send-hook rules have to be on one line--if, like myself, you have vi, for example, set to wrap at 73 characters, temporarily unset it.

Another situation is if John wants everything going to a particular domain to use one header. For example, he belongs to mail@mailist.com, mai12@mailist.com and mail3@mailist.com. He wants everything going to all these mailing lists to be sent through isp1.com rather than his default of isp.com He could make separate send-hooks for each list, however, he can also do it this way.

send-hook ".*.mailist.com" "my_hdr john@isp1.com"

send-hook ".*.mailist.com" 'set sendmail "/usr/bin/nbsmtp -d isp1.com -f john@isp1.com -h smtp.isp1.com"'

Now, all email going to mailist.com, regardless of whatever is to the left of the @ sign will use the isp1.com header and smtp server.