Wow ! i did it in the end, getting Postfix to simply send emails ! That shouldn't be that hard, but somehow, i never had the courage to rtfm to the end. Well, first of, the documentation on the Ubuntu Server Guide is somehow lacking for the very simple task i was trying to achieve. Here's the magic recipe !
Note 1: this howto does not intended to set up a POP3/SMTP server, but only to make Ubuntu send emails, nothing else (to get backup log results from different servers i'm administering). It's done using the version 2.6.5-3 of Postfix.
Note 2: you need a valid email account (and preferably not a free one like gmail, but the kind of your ISP gives you), which means you need to know the address of your SMTP server (smtp.myisp.com), and have a pair login:password that fits.
Note 3: if you don't like vi (and especially if you're working locally) feel free to use any text editor, like gedit on Gnome, for instance.
1) Install/upgrade postfix
sudo aptitude install postfix (1)
2) Configure it
sudo dpkg-reconfigure postfix
and set it as follow:
| General type of mail configuration | Satellite system |
| System mail name | mycomputer.local (2) |
| SMTP relay host | smtp.myisp.com (3) |
| Root and postmaster mail recipient | your unix username (4) |
| Other destinations to accept mail for | mycomputer.local (5) |
| Force synchronous updates on mail queue? | No |
| Local networks | leave this blank |
| Mailbox size limit (bytes) | 0 |
| Local address extension character | + |
| Internet protocols to use | ipv4 (6) |
3) Edit main.cf
sudo vi /etc/postfix/main.cf
after the line relayhost = smtp.myisp.com add this :
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_generic_maps = hash:/etc/postfix/generic
4) Create/edit sasl_passwd
sudo touch /etc/postfix/sasl_passwd
sudo chmod go-rwx /etc/postfix/sasl_passwd
sudo vi /etc/postfix/sasl_passwd
add/write the line:
smtp.myisp.com login:password (7)
then:
sudo postmap /etc/postfix/sasl_passwd
5) Create/edit generic
sudo vi /etc/postfix/generic
add/write the line where senderemail is the name you want, this will be used in th "from" field of all emails that will be sent by postfix, the only important thing being that myisp.com is a valid mail domain:
@mycomputer.local senderemail@myisp.com
then:
sudo postmap /etc/postfix/generic
6) Reload postfix and test
sudo postfix reload
To test it, issue this command (sending an email only with the name of the machine):
echo `date` on `hostname`|sendmail myemail@myisp.com
You should receive an email in your myemail@myisp.com inbox account from senderemail@myisp.com. If not, troubleshooting is made easy by looking at: /var/log/mail.log with your favorite text editor/log viewer.
Last thing, if you want to have your local mail forwarded to you, add a /home/user/.forward file in your home directory with the email of your choice (and you can do the same for root, /root/.forward).
Notes
- I'll go ahead (yeaah) and pass on the fact that, because of package dependencies -and good ol' logic-, this command could remove something else like exim4, sendmail and other packages that play the same role, that's perfectly ok, if you're the real admin of the machine (ie you know you're not breaking something else). Then again, it could do nothing, or only upgrade because postfix is already there.
- Use any name you want ! it can be any fantasy name, since you're not really going to host a mail server...
- Your isp's SMTP server of course, mhhhh ?
- You're not always root, right ?
- Same as System mail name (TODO: add an explanation)
- But if you know what you're doing, feel free to say all or ipv6
- Don't make me state the obvious