I want to send mails from a bash script and to know that they sucessfully left my server.
There are many ways to send mails from bash (see 1 2 for more possibilities). A common way is to use mail
or mutt
together with the build-in MTA (e.g. postfix
). If one does not run a "true" mailserver, than postfix can be configured as a "smart host" or "satelite system" where it connects to another SMTP server (the so-called relay) and sends everything over this server.
I can assume any MTA. Since I control the server, I am willing to install any MTA which is easy to maintain = has an ubuntu (18.04 LTS and newer) and centos (7.4 and newer) package. Right now I am using postfix, since I know it okay and the setup as a relay is quite simple.
Assuming such a setup, I want to write a bash script which sends a mail and then awaits the confirmation that sending it to the relay was successfull. My problem is the last part.
echo "hello world" | mail -s "a subject" [email protected]
#
# Check that the mail has arrived at the relay server. But how?
#