Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Do you have a mail server elsewhere on the LAN? If this is the case, you'll be fine with nullmailer. Also, a mail sent to the server is supposed to trigger an action or you want to send email from the server using command line? – 0xC0000022L Feb 13 '13 at 21:34
Do you want to send a notification by email when your script completes? – roadmr Feb 13 '13 at 21:35
oh my apologies sent FROM the server. No mail server on my LAN yet. Im still debating on what to deploy. – Darth_Vader Feb 13 '13 at 21:36
up vote 3 down vote accepted

The standard way to send an email from a shell script is the mail command, which is provided by the bsd-mailx package. To use it, you do something like:

echo 'This is the message.' | mail -s 'Subject line here'

For more control, the standard way is the sendmail command. The mail command is actually just a wrapper that calls sendmail 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:

  1. Select and install an MTA. If just for outbound mail from shell scripts, then nullmailer is a good choice.

  2. Install the bsd-mailx package and then use mail to send email from your shell script.

share|improve this answer
you stated that sendmail is for mail only. I would assume by that comment you can not send attachments either? – Darth_Vader Feb 14 '13 at 13:50
Emails with attachments are sent with the same stack. Once it is put together, sendmail will still send them. How to put together an email with attachments is really an entirely separate question. – Robie Basak Feb 14 '13 at 15:22
thanks I will do some Google searching before I post that question. – Darth_Vader Feb 14 '13 at 15:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.