Local Mail Only SetupDisclamer: 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

1. Postfix
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:

emerg postfix

If you've just installed gentoo, its likely that you have ssmtp installed, and portage will complain about it. So just unmerge ssmtp and it should be happy. Once thats done, you'll have to set up postfix. Open up your favorite editor (it better be vim) and open /etc/postfix/main.cf. Now the lines to look for look like this.

Code:

#/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

# 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

All you do here is just change - myhostname = localhost and mydomain = localdomain, exactly like that. Simple right? Well, now I use Kmail, and it uses a maildir type format, and I like all daemon emails to be sent to /home/username/Mail/SystemMail (i'll get to covering how kmail can handle this in the next part), so i also look for the line in main.cf that looks like this:

at the bottom of those comments. Make sure you use the trailing / if your using a mailder format. Now this means that all my emails from my daemons will be sent to /home/snakattak/Mail/SystemMail/new. If your going to use my example for the home_mailbox, then you should probably create /home/username/Mail directory. Also, if you don't run as root all the time, now would be a good idea to make your aliases in /etc/mail/aliases. Just change these to feilds to look like mine, using your username of course and just add them somewhere if they aren't already there.

2. 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:

#!/bin/bash
#This script will back up all of my pictures,
#homework, and documents to another mounted
#filesystem

To add this script to your crontab, make sure your in the cron group first, just type

Code:

snakattak@snakshak / # crontab -e

and add this line

Code:

5 4 * * 7 /home/snakattak/bin/backup

That should be it. Now, every sunday at 4:05 AM, cron will run this script and will email me the results with an email that says

Quote:

Cron <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

This 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. Enjoy _________________Ban Reality TV!
Adopt an Unanswered Post

I'll leave my tip posted, but here is a much more thorough guide that bewulf wrote up to do a lot more stuff than just local mail, and his too is aimed at the the home computer as well._________________Ban Reality TV!
Adopt an Unanswered Post

1. First thing we do is create a new account (Configuration->Create new account...).
2. Fill out the Personal Information and set a name for the account.
3. In the server information, change Protocol to IMAP4.
4. Change the server for both receiving and sending to [IP] or localhost
5. Fill in User ID and Password with the Server user's username and password that you use to login to Courier-IMAP.
6. Under the "Send" tab, make sure to check off the SMTP Authentication (SMTP AUTH) option. Next fill in your username and password .

Click the OK button and you're all set. Check your email and send out a test email to yourself

This is a great tip and exactly what I was looking for. After a few mistakes on mypart, I finally got KMail to recieve the mail!

However: Although the emails show up in KMail, when I click them (as to open them/highlight them) the message sort of "disappears," and the subject line changes to "No Subject," the Sender becomes "unknown" and the date also becomes "unknown". I can see the mail arrive in my Mail/SystemMail directory, for example:

But after clicking on them in Kmail, they disappear and my mail directories (cur, new, tmp) are empty. I thought it might be a permission error, but the permissions appear to be correct...any help would be really appreciated!

Yeah it's *really* odd. I did a complete reinstall of my system today, so I'll try everything again. I'm using KDE-3.1.3.

Hrm, well, I reinstalled but it didn't seem to fix anything. The permissions on my /home/vlad/Mail/SystemMail directory are the same, as are my aliases and mail.cf files. Could you post your SystemMail directory permissions please?

Yeah it's *really* odd. I did a complete reinstall of my system today, so I'll try everything again. I'm using KDE-3.1.3.

Hrm, well, I reinstalled but it didn't seem to fix anything. The permissions on my /home/vlad/Mail/SystemMail directory are the same, as are my aliases and mail.cf files. Could you post your SystemMail directory permissions please?

Well, it might not be a permissions problem, maybe your computer clock is off or something. But anyways,

You could also look in ~/.kde/share/apps/config/kmailrc. I think you might have to hand edit something in that file, or add modify the SystemMail entry. I think I might have had to do that, but maybe not, it was a long time ago. Try and make it look like other folders in the file. Hope that helps, thats a really annoying problem._________________Ban Reality TV!
Adopt an Unanswered Post

Just fixed it. One of the things I had done to get KDE to check for new mail was create an account for recieving mail from the SystemMail maildir. HOWEVER: I had made the place where mail is checked from (Mail/SystemMail/) the same as the destination KMail folder (also SystemMail). It must have been clobbering the mail.

This is just a hack to get my KMail to do interval mail checking (I'm assuming yours does it automatically...for whatever reason, my KMail would *NOT* see new mail unless I closed and reopened KMail). I know, it's confusing.

Anyways, I have one maildir that mail gets dumped into by postfix (SystemMail) and ANOTHER maildir that KMail dumps mail into from the postfix maildir. I guess as long as it works...=P Thanks for your help!

Anyways, I have one maildir that mail gets dumped into by postfix (SystemMail) and ANOTHER maildir that KMail dumps mail into from the postfix maildir. I guess as long as it works...=P Thanks for your help!

Glad you worked somethign out. I should also mention, that my kmail never actually checks the mail in the folder. Only when I click on the "SystemMail" folder in Kmail, does it show I have new mail (but I don't have to restart kmail). The reason it doesn't check and update, is because the mail is already there. Your basically tricking kmail, or to put it a better way, just using kmail to read the cron or whatever emails that are *already* there, but kmail doesn't know about it untill you click on the "SystemMail" folder to view. When you do that, its like "oh hey, there's some emails in here I didn't know about, I didn't put them there, oh well, you can still read them" I guess I should've mentioned that before too, but I think I just didn't fully understand your problem. But your trick actually makes it check, which is convenient. There are also probably a lot of other email clients that can handle this sort of setup better, but kmail is what I use because I use kde. If this is really an annoyance to you, you should probably check them out, maybe post here too if you find one that handles this postfix setup better. Sorry about the misunderstanding, I should've said this stuff about kmail in my origional post._________________Ban Reality TV!
Adopt an Unanswered Post

postfix is really tearing my brain to shreds, and it shouldnt. this is really annoying. i have main.cf and master.cf configured correctly, and postfix loads great, but my problem is that smtp is not really listening on port 25. how do i get it to listen on port 25? i went through my conf files a million times, and made a smtpd.cf, smtp.cf, and ssmtp.cf, but still smtp does not listen? i telnet to port 25 and i dont get a mesg saying this is smtp server or whatever it says, and nothing is happening? ahhhh, im going to go crazy, can some one help me please? _________________-Mario

My local mail is working great now. The only problem is that postfix will forward mail to destinations off of localhost. If I use mutt to send an email to a real Internet email address, postfix sends it to my ISP's mail server.

How do I restrict postfix to only send or deliver mail within the local host? Any mail addressed for any other destination should just get bounced back._________________Darrell Bellerive
VA7TO

Eeek! Sorry to bring this back from the dead, but I really think it should be stickied!

Anyway, the above postfix configuration works wonderfully for me, and sending local mail to other users via "mail" (from the mailx package) works well, as do messages from cron.

However, on my Debian system I'm used to being prompted by a "you have new mail" on the command line (no GUI's on these machines; mail is just used as a way of keeping tabs on cron); you then run "mail" and up pop your new messages. The messages sit there nicely in ~/.maildir/new/ and I have to grep for them manually, which is a bit irritating. Running "mail" just says "No mail for root/username/whatever", so I guess it's not checking the maildirs, and checking the mail spool instead. ALthough I can't for the life of me figure out how to get postfix to leave mails in /var/spool/username.

I've been mucking around with my postfix and mail configs, and can't find any easily obvious way to enable this; does anyone on the forums know how to fix this issue?

Now that I have this set up, I would like to be able to use this when PHP sends email. What is the command to send email to a local user with postfix?_________________Yesterday was the deadline for all complaints

procmail is for processes to send mail to the systems mail spool i believe
postfix -what exactly does it do in the scheme of mail
ssmtp...or nb-smtp..

and finally. Making local mail work with Mutt.

I've got various parts of a mail system working before. Some of the concepts I haven't quite got... I 'd like a bit of clarification on the whole system please._________________//Take this barrel and end this struggle