I am looking for a mail option on my Ubuntu server that I can code into my shell script to trigger a script completion by email. What is the best way to complete this task code wise and mailer wise? I had hoped Outlook would work but I see wine indicates it as bad. The email accounts will be work accounts. This will be my first time setting up email function in a Linux box. I have typically used Ubuntu as a mod server for files.
EDIT: Im looking to send FROM the server when the script is complete. If any better suggestions are available I am open to change.
The standard way to send an email from a shell script is the
mail
command, which is provided by thebsd-mailx
package. To use it, you do something like:For more control, the standard way is the
sendmail
command. Themail
command is actually just a wrapper that callssendmail
with a correctly formatted email.The
sendmail
command is the standard Unix interface to the mail transport agent (MTA) on a Unix system. Traditionally, all Unix systems have one. But since they generally need configuring, neither Ubuntu desktop nor server install one by default. So you need to install an MTA yourself.Postfix and Exim are probably the two most popular MTAs right now. Both are packaged well and work fairly easily out of the box. But they're full featured. They can be configured minimally, and the package helps you do this automatically, but the documentation you'll find online will generally assume that you have full MTA functionality configured (eg. mailboxes for incoming email and so forth).
If you just want to send outbound email, then nullmailer is a good choice. It is a minimal MTA designed to provide the standard
sendmail
interface so everything up the stack will work fine, except it sends mail out only.Postfix, Exim are all in main, so are well supported in Ubuntu. nullmailer is in universe, so is community supported only.
So to summarise:
Select and install an MTA. If just for outbound mail from shell scripts, then nullmailer is a good choice.
Install the
bsd-mailx
package and then usemail
to send email from your shell script.