Reading UTF Characters In HTML Mail

For understandable reasons Debian Mutt shows HTML attachments by piping them through links -dump. For inexplicable reasons the Czech lads responsible for the horrendously named (Twibright) links have made it very hard for me to figure out how to get, say, Czech characters. Moving on.

The answer I’m going with is to put a ~/.mailcap file in place that contains the following.

text/html; w3m -T text/html; copiousoutput

That seems to be the default location for Mutt to check for. I had fixed this and it spontaneously got unfixed. Putting this mailcap file in re-fixed it.

Finding Your Mail Server

This list of common mail servers might be helpful. If that doesn’t clear things up, then you can guess at your mail server.

First, find your real IP address as the outside world knows it. I’m using the website my-i-p.com here on the command line but you can just put it in a normal browser if that’s convenient:

$ lynx -dump my-i-p.com | grep "My ip address"

Find out who your ISP is with reverse lookup:

:-> [prince][~]$ nslookup 76.124.159.147 | grep name
147.159.124.76.in-addr.arpa name = c-76-124-159-147.hsd1.nj.comcast.net.

Guess what the mail server might be:

:-> [prince][~]$ nc smtp.comcast.net 25

If that works and you get a mail server greeting message, you are ready to interact with it to test it.

Explicit Mail Server Test

The first thing you need to do is verify you have a cooperating mail server. This process allows you to check on the functionality of a putative mail server from the command line with no ambiguity.

220 OMTA11.westchester.pa.mail.comcast.net comcast ESMTP server ready
HELO just setting up my mail and testing the server
250 OMTA11.westchester.pa.mail.comcast.net hello [76.124.159.147],
pleased to meet you
MAIL FROM: xampl@example.xed.ch
250 2.1.0 <xampl@example.xed.ch> sender ok
RCPT TO: example@gmail.com
250 2.1.5 <example@gmail.com> recipient ok
DATA
354 enter mail, end with "." on a line by itself
This is a test message from a comcast server.
.
QUIT

Debian/Ubuntu

Sending Mail

nullmailer

I believe that the concept of nullmailer is that instead of your server talking to all the wild mail servers around the world, you only talk to one which you have some control over. The huge advantage of this is that you can hire a good mail handling company to do a good job of it and avoid the predations of your ISP or a Silicon Valley tech giant.

The reason you do not want to really run a mail server yourself (unless you’re a professional and that’s your job) is that mail server minutia is so baroque and a such a slippery moving target — because of spam — that to stay on top of it really is a full time job. When running your own mail server, it seems like every month a major provider starts bouncing your messages because you’ve not adopted some kind of new header or registered yourself with some list or god-knows-what.

I tend not to trust Google or my ISP who would probably let you send mail without too much fuss. But a third party professional who is working for you to provide email services seems better to me.

When I do apt install nullmailer I get this message which is helpful in understanding how all this works:

The following packages will be REMOVED:
  exim4-base exim4-config exim4-daemon-light
The following NEW packages will be installed:
  nullmailer

I made a "mailbox" account (using the main account for my hosting provider which handles my email) for the purpose of configuring a constant SMTP server that is independent of any particular predatory ISP. In other words, I pay these people money and they do a good job at receiving and sending my mail without selling me out to criminals. They have a concept of "mailboxes" which I don’t really understand completely; I used a "mailbox" to make a dedicated account just to send things so that credential set was not terribly important to me. If this credential set gets compromised some spammers can send a bit of mail using my outbound pipeline. That’s it.

In the Debian installation, it stops and asks you to enter a "Smarthost" which is just a way to say "flexibly interpreted way to send mail".

Add this line:

mail99.mygoodisp.com smtp --port=465 --user=mysmtponly@xed.ch --pass=StupidPlainText --ssl

Or if you’re doing things manually, add that line to this file.

/etc/nullmailer/remotes

The password as shown for illustration is StupidPlainText which is lame, but the whole point of this account is that it doesn’t really do anything but let me send mail. It deals with the problem that the password must be insecure in plain text in the nullmailer/remotes file anyway. Search for "smtp" in my secure notes for the real thing.

If you’re using apt, it’s probably ready to go. If not, you might need to restart the mailer.

sudo service nullmailer restart
sudo service nullmailer status

Test it out.

cal 2021 | mail -a "From: REMINDER <ra21@chrisnotarealdomain.com>" -s "TESTING ra21" cxe-ra21@chrisnotarealdomain.com

sendEmail

One easy solution to send things is sendEmail:

$ sudo apt-get install sendemail
$ sendEmail -f xampl@example.xed.ch -t example@gmail.com -u "Test message of sendEmail on pr" -s smtp.comcast.net <<<"This is a test message."
Reading message body from STDIN because the '-m' option was not used.
If you are manually typing in a message:
    - First line must be received within 60 seconds.
    - End manual input with a CTRL-D on its own line.
May 15 13:39:36 prince sendEmail[21947]: Message input complete.
May 15 13:39:37 prince sendEmail[21947]: Email was sent successfully!

This can be a good way to test the server.

msmtp and mailx and exim4

Presumably exim4 is already installed because it usually is I think.

$ sudo apt-get install msmtp mailx
$ sudo dpkg-reconfigure exim4-config
 internet site; mail is sent and received directly using SMTP
 mail name= example.xed.ch
 listen on= 127.0.0.1 (unless you really want outside mail traffic)
 recipient domains= <empty>
 recipient relay= <empty>
 uncond relay= <empty>
 DNS minimal= No
 delivery format= mbox
 split config= No
 aliases for postmaster and root= "xed postmaster-pr@example.xed.ch"

Then create this file /etc/msmtprc containing:

account cox
host smtp-server.san.rr.com

account default : cox

Or:

account comcast
host smtp.comcast.net

account default : comcast

Now test:

$ mail -s "test of pr exim cli mail" example@gmail.com <<<"This is a test `date`"

And troubleshoot:

$ cat /var/log/exim4/mainlog

Email With Gentoo

Packages Relevant For Email

mail-mta/sendmail

Widely-used Mail Transport Agent (MTA).

mail-mta/postfix

A fast and secure drop-in replacement for sendmail.

mail-client/mailx

The /bin/mail program, which is used to send mail via shell scripts.

mail-mta/ssmtp

Extremely simple MTA to get mail off the system to a Mailhub

mail-mta/msmtp

An SMTP client and SMTP plugin for mail user agents such as Mutt.

net-mail/sendEmail

Command line based, SMTP email agent.

net-mail/email

Advanced CLI tool for sending email.

Note
mail-client/mailx is important for command line /bin/mail to work with the MTA that is installed (sendmail, postfix, etc).

A Simple Homemade Mail Client

xed_mutt_puppy.py
#!/usr/bin/python
# Here is a quick and dirty mail client designed to just see mail.
# This was written when the route between my house and mail server was
# blocked for some weird reason. I was able to use this on an ssh
# account to look at some critical mail.
import getpass, imaplib

theuser= 'xed'
thepass= getpass.getpass()
mail_server= 'mail66.theisp.com'

#M= imaplib.IMAP4()
M= imaplib.IMAP4_SSL(mail_server)

M.login(theuser, thepass)

M.select()

typ, data= M.search(None, 'ALL')

for num in data [0].split():
    typ, data = M.fetch(num, '(RFC822)')
    print 'Message %s\n%s\n' % (num, data[0][1])

M.close()

M.logout()