Sending mail from the terminal [SOLVED]

I use the mail command to send myself messages from automatically-running scripts so that I know that all is OK – or not. It’s helpful also as I look after the computing needs of several elderly people, and if they haven’t backed-up or updated for a while I can give a gentle nudge to do so.

This arrangement worked well for several years until the recent spate of security legislation prompted internet organisations such as email providers to improve their (and our) security, and then nothing worked. And some mail routines such as mpack and swaks are no longer available in Ubuntu.

I’ve got the basic mail routine working now. For example:
mail -s “$USER has backed up” -r my.name@runbox.com my.alias@runbox.com < message-file.txt
where
my.name@runbox.com (“From”) is my registered address with Runbox.com
my.alias@runbox.com (“To”) is an alias address I have with Runbox.com
message-file.txt is the text to appear in the body of the email.

This works well, except that I can send email only to myself (ie to any of my Runbox email accounts), not to any other such as my secondary email account at Protonmail.com or to friends. When sending mail to my.name@proton.me there are no errors reported but the mail does not arrive.

My question is: are any of our readers able to use the mail command to send mail to other people? And if so, can you tell me where I am going wrong?

Thanks.
Keith

apt install postfix

:slight_smile:

Then if you need a relay host, I could recommend “sendinblue.com”.

I haven’t tried that one - I’ll give it a go.

Thanks,
Keith

If you install postfix it should “just work”, however most recipients will likely treat email from you as spam. If you add sendinblue as a relay host, you should be able to send email with a reasonable degree of “reputation”. I think their free tier allows up to 100+ a day … maybe more now, it’s a while since I looked and I think they increased it.

That’s exactly what happens, except in a subtle way. It seems that BT (which owns all the infrastucture) comms-servers that relay messages to the email provider add a token to the message that is interrogated at the email provider’s server which can then decide whether or not to discard it - and they always do. There is an intermediary that companies like BT register with that does all the fancy work. I forget all the details but Runbox did a lot of work to help me understand the process. If I can find the details I report here just out of interest.

I’ll have a look at “sendinblue”

May thanks for the info.

Keith

Mmm, it’s actually way worse than that. There are a whole series of “RBL” 's out there which all the mail providers (including us) use to block spam. One of those references an IP whitelist so unless you are on the whitelist of IP addresses, mail from you is automatically rejected. I think M$ are quite big in this area. So any IP range related to ADSL, broadband or dialup, automatically “not” on the whitelist. More recently, any IP range with hosting providers like Amazon or Digital Ocean (like us), automatically not on the whitelist. So you can’t even rent a virtual server these days and run a mail server on it.

Not hopeful, then. I haven’t tried postfix yet - I’ll report back on that…>

keith@E5570:~$ sudo apt install postfix

[sudo] password for keith:
Reading package lists… Done
Building dependency tree
Reading state information… Done
Package postfix is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package ‘postfix’ has no installation candidate
keith@E5570:~$

I am guessing the “another package” is “sendmail” which almost all other mail apps use. I can use it, and it has a useful “verbose” option but so far “mail” is the best for me.

Keith

Mmm, wouldn’t recommend “the” sendmail package. Postfix is a drop-in replacement (i.e. it pretends to be sendmail) so unless you have a custom sendmail configuration, you should be able to just remove sendmail and replace it with postfix. Just pay attention when removing sendmail in case they’ve screwed up the dependencies and linked it to something you don’t want to remove.
Sendmail was one of (the?) first mail package, take a look at the config docs, it’s pretty horrible. As far as I’m aware postfix is the standard / default these days, better design, better security, better compatibility etc … (from memory, I think it was initially developed and contributed by IBM)
“mail” is a local delivery program, it will use the installed “sendmail” (i.e. sendmail or postfix) to send mail “off” the machine.

you should be able to just remove sendmail and replace it with postfix
.............except that trying to install it results in:
Package 'postfix' has no installation candidate
so doesn't look very much like a standard for Ubuntu.

Were you suggesting that I might be able to install Postfix only if I uninstall Mail/Sendmail?

Ok, so either you’re not running Ubuntu, or Ubuntu is badly broken in some way. If you google “what is the default sendmail package on Ubuntu”, it will answer “Postfix is the default Mail Transfer Agent (MTA) in Ubuntu. It attempts to be fast and secure, with flexibility in administration.” Works on all my boxes and installed by Ubuntu installer as part of the initial installation on a server or full-fat desktop.

Postfix is a replacement for sendmail, hence you can only install one of them. I’ve no idea how you managed to get sendmail installed, I might suspect “apt install sendmail” on a system that was installed “without” mail.

$ apt show postfix 
Package: postfix 
Version: 3.3.0-1ubuntu0.4 
Priority: optional 
Section: mail 
Origin: Ubuntu 
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> 
Original-Maintainer: LaMont Jones <lamont@debian.org> 
Bugs: https://bugs.launchpad.net/ubuntu/+filebug 
Installed-Size: 4,078 kB 
Provides: default-mta, mail-transport-agent 
Depends: libc6 (>= 2.14), libdb5.3, libicu60 (>= 60.1-1~), libsasl2-2, libssl1.1 (>= 1.1.0), debconf (>= 0.5) | debconf-2.0, netbase, adduser (>= 
3.48), dpkg (>= 1.8.3), lsb-base (>= 3.0-6), ssl-cert, cpio, e2fsprogs 
Recommends: python3 
Suggests: procmail, postfix-mysql, postfix-pgsql, postfix-ldap, postfix-pcre, postfix-lmdb, postfix-sqlite, sasl2-bin, libsasl2-modules, dovecot-c
ommon, resolvconf, postfix-cdb, mail-reader, ufw, postfix-doc 
Conflicts: mail-transport-agent, smail 
Replaces: mail-transport-agent 
Homepage: http://www.postfix.org 
Task: mail-server 
Supported: 5y 
Download-Size: 1,147 kB 
APT-Sources: http://gb.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages 
Description: High-performance mail transport agent 
 Postfix is Wietse Venema's mail transport agent that started life as an 
 alternative to the widely-used Sendmail program.  Postfix attempts to 
 be fast, easy to administer, and secure, while at the same time being 
 sendmail compatible enough to not upset existing users. Thus, the outside 
 has a sendmail-ish flavor, but the inside is completely different

That’s interesting.
Here are the first few lines of inxi:

keith@E5570:~$ inxi -Fx
System:    Host: E5570 Kernel: 5.15.0-56-generic x86_64 bits: 64 compiler: N/A Desktop: Gnome 3.36.9 
           Distro: Ubuntu 20.04.5 LTS (Focal Fossa) 
Machine:   Type: Laptop System: Dell product: Latitude E5570 v: N/A serial: <superuser/root required> 
           Mobo: Dell model: 01D4DJ v: A00 serial: <superuser/root required> UEFI [Legacy]: Dell v: 1.29.4 
           date: 12/21/2021 

…which shows I really am running Ubuntu - albeit not the latest version.

And:
keith@E5570:~$ apt show postfix
Package: postfix
State: not a real package (virtual)
N: Can’t select candidate version from package postfix as it has no candidate
N: Can’t select versions from package ‘postfix’ as it is purely virtual
N: No packages found
keith@E5570:~$ apt show sendmail
N: Unable to locate package sendmail
N: Unable to locate package sendmail
E: No packages found
keith@E5570:~$ apt show mail
N: Unable to locate package mail
N: Unable to locate package mail
E: No packages found
keith@E5570:~$

…which is even more interesting, as I really can send mail using the mail command - just not to anyone other than myself.

Ok, so either you’re not running Ubuntu, or Ubuntu is badly broken in some way.

So postfix and sendmail show show packages, “mail” is a program rather than a package so the output there is right. “mail” comes from the “mailutils” package, so “apt show mailutils” should work.

I’d start with “sudo apt update” and work from there. “apt” is in some way borked, so assuming apt update doesn’t fix it, take a look at /etc/apt/sources.list and compare it to another machine. Most likely fix is to get a reasonable copy of “sources.list” then run apt update.

apt show mailutils…>

keith@E5570:~$ apt show mailutils
Package: mailutils
Version: 1:3.7-2.1
Status: install ok installed
Priority: optional
Section: mail
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Jordi Mallach <jordi@debian.org>
Installed-Size: 630 kB
Provides: mail-reader, mailx
Depends: mailutils-common (= 1:3.7-2.1), guile-2.2-libs, libc6 (>= 2.14), libcrypt1 (>= 1:4.1.0), libfribidi0 (>= 0.19.2), libgc1c2 (>= 1:7.2d), libgnutls30 (>= 3.6.5), libgsasl7 (>= 1.1), libkyotocabinet16v5 (>= 1.2.76), libldap-2.4-2 (>= 2.4.7), libmailutils6, libncurses6 (>= 6), libpam0g (>= 0.99.7.1), libpython3.8 (>= 3.8.2), libreadline8 (>= 6.0), libtinfo6 (>= 6), libwrap0 (>= 7.6-4~)
Recommends: default-mta | mail-transport-agent
Suggests: mailutils-mh, mailutils-doc
Breaks: bsd-mailx (<< 8.1.2-0.20071201cvs-1), bsdmainutils (<< 8.0.6), elm-me+ (<< 2.4pl25ME+99c-3), heirloom-mailx (<< 12.3-3)
Homepage: https://www.gnu.org/software/mailutils/
Download-Size: unknown
APT-Manual-Installed: yes
APT-Sources: /var/lib/dpkg/status
Description: GNU mailutils utilities for handling mail
 GNU Mailutils is a rich and powerful protocol-independent mail framework.
 It contains a series of useful mail libraries, clients, and servers.
 .
 This package contains the GNU mailutils versions of dotlock, frm, from,
 maidag, mail, messages, mimeview, movemail, readmsg and sieve. They are
 capable of speaking POP3, IMAP, mbox, MH and Maildir.
 .
  dotlock -- lock mail spool files.
  frm -- display From: lines.
  from -- display from and subject.
  maidag -- the mail delivery agent.
  mail -- the standard /bin/mail interface, mail sender and reader.
  messages -- count the number of messages in a mailbox.
  mimeview -- display files, using mailcap mechanism.
  movemail -- move messages across mailboxes.
  readmsg -- extract selected messages from a mailbox.
  sieve -- a mail filtering tool.

keith@E5570:~$ 

apt update has no effect and /etc/apt/sources.list is empty…>

keith@E5570:~$ cat  /etc/apt/sources.list
keith@E5570:~$

I shall try to find the file from another computer and copy it over.

Also, apt show mailutils shows…

keith@E5570:~$ apt show mailutils
Package: mailutils
Version: 1:3.7-2.1
Status: install ok installed
Priority: optional
Section: mail
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Jordi Mallach <jordi@debian.org>
Installed-Size: 630 kB
Provides: mail-reader, mailx
Depends: mailutils-common (= 1:3.7-2.1), guile-2.2-libs, libc6 (>= 2.14), libcrypt1 (>= 1:4.1.0), libfribidi0 (>= 0.19.2), libgc1c2 (>= 1:7.2d), libgnutls30 (>= 3.6.5), libgsasl7 (>= 1.1), libkyotocabinet16v5 (>= 1.2.76), libldap-2.4-2 (>= 2.4.7), libmailutils6, libncurses6 (>= 6), libpam0g (>= 0.99.7.1), libpython3.8 (>= 3.8.2), libreadline8 (>= 6.0), libtinfo6 (>= 6), libwrap0 (>= 7.6-4~)
Recommends: default-mta | mail-transport-agent
Suggests: mailutils-mh, mailutils-doc
Breaks: bsd-mailx (<< 8.1.2-0.20071201cvs-1), bsdmainutils (<< 8.0.6), elm-me+ (<< 2.4pl25ME+99c-3), heirloom-mailx (<< 12.3-3)
Homepage: https://www.gnu.org/software/mailutils/
Download-Size: unknown
APT-Manual-Installed: yes
APT-Sources: /var/lib/dpkg/status
Description: GNU mailutils utilities for handling mail
 GNU Mailutils is a rich and powerful protocol-independent mail framework.
 It contains a series of useful mail libraries, clients, and servers.
 .
 This package contains the GNU mailutils versions of dotlock, frm, from,
 maidag, mail, messages, mimeview, movemail, readmsg and sieve. They are
 capable of speaking POP3, IMAP, mbox, MH and Maildir.
 .
  dotlock -- lock mail spool files.
  frm -- display From: lines.
  from -- display from and subject.
  maidag -- the mail delivery agent.
  mail -- the standard /bin/mail interface, mail sender and reader.
  messages -- count the number of messages in a mailbox.
  mimeview -- display files, using mailcap mechanism.
  movemail -- move messages across mailboxes.
  readmsg -- extract selected messages from a mailbox.
  sieve -- a mail filtering tool.

keith@E5570:~$

And sudo apt install postfix shows…>

keith@E5570:~$ sudo apt install postfix
[sudo] password for keith: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package postfix is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'postfix' has no installation candidate
keith@E5570:~$

As an aside which might indicate a problem with my OS installation…Ubuntu 20.04 installed on /dev/nvme0n1p5 (which is the name of the solid state drive) rather than sda1. When I plug in a USB device it is mounted as /dev/sda1. Which is very confusing and dangerous when using gparted.

Ok, so my expectation is that with a blank /etc/apt/sources.list, you won’t be able to install or upgrade anything and you will need to restore this file by hand. (once restored, apt update + apt upgrade)

Caveat; /etc/apt/sources.list.d/… contains overrides for third party applications (things like google chrome etc) which if it exists, may allow you to update things listed in this folder.

Either way, if “sources.list” is missing, something “bad” has happened to your machine. Now, it could be missing for “many” reasons, but be aware that removing a machine’s ability to “update” (or replace potentially outdated, broken or infected packages) is something “malware” on occasion does. Typically malware would be relatively intelligent and replace the “apt” command, however I have seen brute force malware in the past remove things “like” sources.list.

Also remember sources.list is release specific, if you install a sources.list from a “different” release, it’s not going to work and it’ll likely cause problems.

You are spot on! For the last ten days or so, My laptop was telling me that my system was up-to-date, but today I had a message telling me to download new files, which I couldn’t. So, yes: the system is screwed.
My only option, it seems is to do a full backup (which I do regularly anyway) and re-install Ubuntu - probably to V22.

I am very careful not to visit dubious websites or download non-standard files so I would be interested to hear of any likely reasons for this problem so I can avoid them in the future. This is the first time that LInux has let me down so I guess I can’t be too critical.

I haven’t forgotten about this - just overwhelmed by summer gardening, DIY and visitors. I’ll get back to it as and when.

Problem solved.

The s/w updating problem indicated corrupted files somewhere so as there was a more recent O/S version available I opted to install Ubuntu 22, which fixed the updating problem.
Of course I had to re-install lots of utilities and odd s/w used by my scripts - in particular Mailutils, and the “mail” command now works perfectly!
Many thanks for all the input.

Keith
(Not sure yet how to mark this topic as solved in the new Forum, but I’ll have a go.)

7 posts were split to a new topic: This topic was split from a publicly visible topic