Disclamer: This is not a comprehensive email tutorial. It is very basic to say the least.
Ok, if your like me, you run behind a firewall at home with other users. And you don't really need sendmail or postfix to send emails because you just use your isp's smtp server, but you do need some sort of email notifications for your system services such cron, snort, or a script you wrote yourself. Now I am no way an expert at any of this, I'm just going to document the steps I took to setup postfix for just local email. I'm doing this because I could never find a tutorial for something like this, everything else out there is for sending and recieving emails to other hosts (correct me if i'm wrong please).
Okay, if your interested in what I am talking about, please read on. If your looking to figure out how to run a mailserver with spam assasin to handle millions of emails a day, etc..., then you'll have to look elsewhere.
The topics i'll talk about are
- Setting up Postfix
- Setting up Kmail
- Simple Cron Example
Postfix is pretty easy to set up, and it seems to be the gentoo way. This part of the guide is mostly taken from here[gentoo.org].
So the first thing you need to do is
Code: Select all
emerg postfixCode: Select all
#/etc/postfix/main.cf
# RECEIVING MAIL
# The inet_interfaces parameter specifies the network interface
# addresses that this mail system receives mail on. By default,
# the software claims all active interfaces on the machine. The
# parameter also controls delivery of mail to user@[ip.address].
#
# See also the proxy_interfaces parameter, for network addresses that
# are forwarded to us via a proxy or network address translator.
#
# Note: you need to stop/start Postfix when this parameter changes.
#
#inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
Code: Select all
inet_interfaces = $myhostname, localhost
mydestination = $myhostname, localhost.$mydomain
Code: Select all
# INTERNET HOST AND DOMAIN NAMES
#
# The myhostname parameter specifies the internet hostname of this
# mail system. The default is to use the fully-qualified domain name
# from gethostname(). $myhostname is used as a default value for many
# other configuration parameters.
#
#myhostname = host.domain.tld
# The mydomain parameter specifies the local internet domain name.
# The default is to use $myhostname minus the first component.
# $mydomain is used as a default value for many other configuration
# parameters.
#
#mydomain = somedomain.com
Code: Select all
# DELIVERY TO MAILBOX
#
# The home_mailbox parameter specifies the optional pathname of a
# mailbox file relative to a user's home directory. The default
# mailbox file is /var/spool/mail/user or /var/mail/user. Specify
# "Maildir/" for qmail-style delivery (the / is required).
#
#home_mailbox = Mailbox
#home_mailbox = Maildir/
Code: Select all
home_mailbox = Mail/SystemMail/
Code: Select all
#/etc/mail/aliases
# Well-known aliases -- these should be filled in!
root: snakattak
operator: snakattak
Code: Select all
root@snakshak / # postfix check
root@snakshak / # newaliases
root@snakshak / # /etc/init.d/postfix start
Code: Select all
root@snakshak / # rc-update add postfix default2. Kmail
To set up kmail is really easy, you just have to Right-click on Local Folders -> New Folder. Give the new folder the same name as you did in your main.cf file, for example mine is SystemMail, so the folder name would be SystemMail. Make sure you select maildir for the Mailbox Format in the same window. Thats pretty much it, you can test it out yourself by sending an email using the sendmail protocal in kmail. Just send it to username or root @localhost.localdomain, and you should get an email in the SystemMail folder in Kmail.
3. Simple Cron Example
Now that you can send emails to only yourself pretty much, its not very useful. But what is useful is getting daemons like cron to report their output. You can add emerge sync to a cron job as root, and you'll recieve an email in your SystemMail directory that shows the entire output of emerge sync. But for my example, I have a backup script I wrote that looks somethign like this:
Code: Select all
#!/bin/bash
#This script will back up all of my pictures,
#homework, and documents to another mounted
#filesystem
cd /home/snakattak/
## Pics
rm -rf /mnt/bacup/backups/pics.tar.bz2
tar -cpf /mnt/backup/backups/pics.tar pics
bzip2 /mnt/backup/backups/pics.tar
echo pics dir backed up
## code / homework stuff
rm -rf /mnt/backup/backups/src.tar.bz2
tar -cpf /mnt/backup/backups/src.tar src
bzip2 /mnt/backup/backups/src.tar
echo code dir backed up
## docs / classes / books
rm -rf /mnt/backup/backups/documents.tar.bz2
tar -cpf /mnt/backup/backups/documents.tar docs
bzip2 /mnt/backup/backups/documents.tar
echo docs dir backed up
Code: Select all
snakattak@snakshak / # crontab -eCode: Select all
5 4 * * 7 /home/snakattak/bin/backupThis tip is a bit overkill, but I know it would've helped me out a bunch when trying to do this. So I hope that others will get some use out of it. If you find an error in this document, please don't hesitate to post so I can fix it. EnjoyCron <snakattak@snakshak> /home/snakattak/bin/backup
From:
root@localhost.localdomain (Cron Daemon)
To:
snakattak@localhost.localdomain
Date:
Today 10:43:19 am
pics dir backed up
code dir backed up
docs dir backed up




