When I try the command in terminal, an email is sent. I have checked there is no local SMTP is running, so what is the mechanism used by Apple behind the scene?
echo "Hello" | mail -s "Test" email@example.com
To see this in action, try
I am not sure this is actually a proper answer to the question because it doesn't explain how Postfix is spawned and torn down, but hopefully it helps answer the question.
SMTP daemons or servers are there to receive mail, not send it. In your example,
However, depending on your mail setup, you may require to log into an outgoing mailserver to authenticate, or if nothing else just to provide sender and return-to addresses etc. Now, you can do all this at the command line by passing the appropriate parameters on the terminal, but as long as you have set up your Mail app, this config is already stored, and by simply temporarily firing up the mail subsystem the terminal commands can grab that info and now have one or more mail smtp servers they can choose to send outgoing messages. It will then terminate the processes when complete.
You can test this all out at the command line and send the mail without having to use a mail client. I'm not at a Mac, so these commands may need editing by someone who is, but you can do this:
Read This for more info on emailing via telnet - it's a great debugging tool
You can check the mail headers
Nevertheless it is not a good idea to use
You can find a solution at SMTP Smart Host Setup for Postfix in Snow Leopard which works for me (also on Lion, Mountain Lion).