# [TIP] Local Mail Only

## snakattak3

Local Mail Only Setup

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

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

```
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.

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

```

 Now, just add two below the comments that say

```
inet_interfaces = $myhostname, localhost

mydestination = $myhostname, localhost.$mydomain

```

Now, find the part in main.cf that looks like this:

```
# 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: 

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

```

Then i just add this line 

```
home_mailbox = Mail/SystemMail/

```

 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. 

```

#/etc/mail/aliases

# Well-known aliases -- these should be filled in!

root:   snakattak

operator:       snakattak

```

 Ok, for me this is all I had to do, next just type 

```
root@snakshak / # postfix check

root@snakshak / # newaliases

root@snakshak / # /etc/init.d/postfix start

```

 And then add it to your default runlevels

```
root@snakshak / # rc-update add postfix default
```

Thats it for Postfix configuration.

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:

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

```

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

```
snakattak@snakshak / # crontab -e
```

and add this line 

```
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)
> ...

 

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  :Smile: 

----------

## snakattak3

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.

----------

## AlterEgo

Thanks for the guide, snakattak3. It's nice and clean.

Q

However, is there a way to use Sylpheed as the receiving mailreader instead of Kmail? 

A

Yes there is, using Courier-IMAP: Emerge courier-imap.

The how-to below is a shameless "keep it simple" adaptation from: 

https://forums.gentoo.org/viewtopic.php?t=56633  :Embarassed: 

```

edit /etc/courier-imap/authdaemond.conf

AUTHDAEMOND="authdaemond.plain"

```

```

edit /etc/courier-imap/authdaemonrc

authmodulelist="authpam"

```

```

edit /etc/pam.d/imap

# PAM setup for

auth       required     pam_nologin.so

auth       required     pam_stack.so service=system-auth

account    required     pam_stack.so service=system-auth

session    required     pam_stack.so service=system-auth 

```

These lines may already exist and all that is required is to uncomment them.  No matter what's in there, make sure your file looks the same as the above code block.

edit /etc/courier-imap/imapd  and check the MAILDIR locations and the forward slash "/" behind it.

```
 MAILDIR=Mail/SystemMail/ 
```

(or your personal location)

Finally:

```

/etc/init.d/courier-imapd start

rc-update add courier-imapd-ssl default 

```

Setting up Sylpheed:

   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

----------

## snakattak3

Thanks  :Smile:  I hope that tip helps others out too.

----------

## Rebes

Helped me out!  thanks!

R!

----------

## rajeshd

This tip helped me perfectly!

Thank you, so much.

-Raj

----------

## Vlad

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:

velius SystemMail # find ./

./

./cur

./new

./new/1061838111.V307Ib88.velius.domain.com

./new/1061838094.V307I93a.velius.domain.com

./tmp

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!

----------

## snakattak3

Thats really strange. What version of kde are you using?

When I get mail to my SystemMail directory, it comes up as

```

Subject - Cron <root@snakshak> /usr/bin/rdate -s time.nist.gov

Sender - Cron Daemon 

And Date - Current Date

```

And when I open the mails it says its from: root@localhost.localdomain (Cron Daemon) and to: root@localhost.

I don't know why its doing that.  I'll keep thinking though.

----------

## Vlad

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?

----------

## snakattak3

 *Vlad wrote:*   

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

```

arusnak@Otto Mail $ ll SystemMail/

total 1.5K

drwx--S---    2 arusnak  users          48 Sep 17 17:23 cur/

drwx--S---    2 arusnak  users         480 Sep 22 08:00 new/

drwx--S---    2 arusnak  users          48 Sep 22 08:00 tmp/

```

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.

----------

## Vlad

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!

----------

## snakattak3

 *Vlad wrote:*   

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

----------

## MarioCorleone

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?  :Rolling Eyes: 

----------

## drb

Thanks snakattak3 for this how-to!

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.

----------

## Braempje

I've been looking for this one for a long time, thanks!

----------

## stdPikachu

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?

----------

## danpixley

I have also found this guide helpful for setting up local mail only:

http://dev.gentoo.org/~spider/local-mail-0.3.0/local-email.html

Dan

----------

## bsodmike

Why oh why does root do this for me:

```

gentoo1 root # mail

/root/: Is a directory

```

I have my email address in aliases under 'root:' so the mail get's to that account fine, but doesn't get to 'root' on the system.  i.e. .maildir isn't created...VERY annoying!

Here is how a test message goes:

```

Jan  4 01:57:41 gentoo1 postfix/pickup[7606]: CDD73C3D06: uid=0 from=<root>

Jan  4 01:57:41 gentoo1 postfix/cleanup[26576]: CDD73C3D06: message-id=<20050103195741.CDD73C3D06@gentoo1.kicks-ass.net>

Jan  4 01:57:41 gentoo1 postfix/qmgr[7607]: CDD73C3D06: from=<root@gentoo1.kicks-ass.net>, size=309, nrcpt=1 (queue active)

Jan  4 01:57:41 gentoo1 postfix/cleanup[26576]: CF263C3CC5: message-id=<20050103195741.CDD73C3D06@gentoo1.kicks-ass.net>

Jan  4 01:57:41 gentoo1 postfix/local[26578]: CDD73C3D06: to=<root@localhost.kicks-ass.net>, orig_to=<root@localhost>, relay=loc al, delay=0, status=sent (forwarded as CF263C3CC5)

Jan  4 01:57:41 gentoo1 postfix/qmgr[7607]: CF263C3CC5: from=<root@gentoo1.kicks-ass.net>, size=455, nrcpt=1 (queue active)

Jan  4 01:57:41 gentoo1 postfix/qmgr[7607]: CDD73C3D06: removed

Jan  4 01:57:45 gentoo1 postfix/smtp[26579]: CF263C3CC5: to=<mike@bsodmike.com>, orig_to=<root@localhost>, relay=bsodmike.com[64 .235.234.100], delay=4, status=sent (250 OK id=1ClYKm-00034P-5x)

Jan  4 01:57:45 gentoo1 postfix/qmgr[7607]: CF263C3CC5: removed

```

This is the config for postfix:

```

gentoo1 root # postconf -n

alias_database = hash:/etc/mail/aliases

alias_maps = hash:/etc/mail/aliases

command_directory = /usr/sbin

config_directory = /etc/postfix

daemon_directory = /usr/lib/postfix

debug_peer_level = 2

default_destination_concurrency_limit = 2

home_mailbox = .maildir/

html_directory = no

inet_interfaces = all

local_destination_concurrency_limit = 2

mail_owner = postfix

mail_spool_directory = /var/spool/mail

mailq_path = /usr/bin/mailq

manpage_directory = /usr/share/man

mydestination = $myhostname, localhost.$mydomain, $mydomain

mydomain = {not shown}

myhostname = gentoo1.{not shown}

mynetworks = 10.0.0.0/8, 127.0.0.0/8

mynetworks_style = subnet

myorigin = $myhostname

newaliases_path = /usr/bin/newaliases

queue_directory = /var/spool/postfix

readme_directory = /usr/share/doc/postfix-2.1.5-r1/readme

sample_directory = /etc/postfix

sendmail_path = /usr/sbin/sendmail

setgid_group = postdrop

unknown_local_recipient_reject_code = 450

```

Any help would be great, thanks!

Mike

----------

## sleek

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?

----------

## evader

I've been trying to work out how to do my local mail for ages.

Thanks a lot.

----------

## kenyon

Awesome, thanks for the writeup!

----------

## evader

Could someone please go over a few things.

MTA/MUA !?!?

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.

----------

## vdboor

BTW, if you want your local mail to be passed through maildrop (a procmail replacement) first, use this instead of home_mailbox:

```
mailbox_command = /usr/bin/maildrop

local_destination_concurrency_limit = 1
```

 :Smile: 

----------

## kenyon

 *evader wrote:*   

> Could someone please go over a few things.

 

OK, I'll try.

 *Quote:*   

> MTA/MUA !?!?

 

MTA = Mail Transfer Agent.  That would be postfix, sendmail, qmail, etc.  The program that actually does the transfer of mail.

MUA = Mail User Agent.  That is KMail, Thunderbird, Mutt, etc.  You write your mail here and it's delivered to the MTA.

 *Quote:*   

> procmail is for processes to send mail to the systems mail spool i believe

 

Yes, but procmail first can do some processing of the mail.  You don't need it, as this guide demonstrates.

 *Quote:*   

> postfix -what exactly does it do in the scheme of mail
> 
> ssmtp...or nb-smtp..

 

Postfix is an MTA.  Ssmtp and nbsmtp aren't really MTAs, they just get mail off the local system.  Read the documentation on each of those.  See also esmtp.

 *Quote:*   

> and finally. Making local mail work with Mutt.

 

Either use this guide, or use ssmtp/nbsmtp/esmtp and the documentation for those.

Hope this helps.

----------

## evader

Thanks.

I think Im on the right path now. Need to read some more man pages.  :Very Happy: 

 *Quote:*   

> Gentoo: Use the source

 

----------

## jd5419

I'm totally TOTALLY tired of trying to get mail to work. I've tried setting up mail on multiple different computers multiple different times (until i get too frustrated to continue) I followed this tutorial, and about a dozen others and it just ISN'T working. Here is my main.cf:

queue_directory = /var/spool/postfix

command_directory = /usr/sbin

daemon_directory = /usr/lib/postfix

mail_owner = postfix

myhostname = localhost

mydomain = localdomain

inet_interfaces = $myhostname, localhost

mydestination = $myhostname, localhost.$localdomain

unknown_local_recipient_reject_code = 550

home_mailbox = Mail/

debug_peer_level = 2

debugger_command =

         PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin

         xxgdb $daemon_directory/$process_name $process_id & sleep 5

sendmail_path = /usr/sbin/sendmail

newaliases_path = /usr/bin/newaliases

mailq_path = /usr/bin/mailq

setgid_group = postdrop

html_directory = no

manpage_directory = /usr/share/man

sample_directory = /etc/postfix

readme_directory = /usr/share/doc/postfix-2.1.5-r2/readme

default_destination_concurrency_limit = 2

alias_database = hash:/etc/mail/aliases

local_destination_concurrency_limit = 2

alias_maps = hash:/etc/mail/aliases

I really dont even know whats going on with the thing but it says i have no mail when i type mail, and also nothing is in the maildir and i'm totally stumped.

----------

## snakattak3

Try making the maildirectory if its not there, and create an empty file, probably has to be your username, or the one the mail goes to, and then change the permissions on that file so it is accessible by your user. Also, I remember doing this a couple of months ago upgrading postfix, but there may be a line down at the end of the "main.cf" file that conflicts with the settings you make using this tip. Don't give up, read the man pages, and ask in irc sometimes for help. The more specific your question is, the more likely you'll get an answer that helps. Start with small steps to get things working, work out one problem at a time, and eventually you'll reach your main problem.. witch seems to me that you can't get your local mail working. Every tutorial on these forums is different, so stick to one method, if you jump around trying everyone's different configurations at once, of course it won't work. Try asking us a more specific question, then we can try (and be more willing) to help you out.

----------

## panlm

 *danpixley wrote:*   

> I have also found this guide helpful for setting up local mail only:
> 
> http://dev.gentoo.org/~spider/local-mail-0.3.0/local-email.html
> 
> Dan

 

i love your post, i forgot to emerge procmail

----------

## cgmd

snakatttake3... 

This is exactly the thread I've been seeking, but my efforts to get things working have been thwarted, so far (likely due to my own ignorance)!

I know it's been a long while since a post to this thread, but I'm hopeful someone will lend me an ear... 

Postfix setup and launch went according to plan.

Things then fell apart when I attempted following the setup instructions for Sypheed (because I don't have KDE or Kmail on the machine already).

The first issue was discovering a lack of the 2 courier-imap files needing to be edited: 

```

Code:

edit /etc/courier-imap/authdaemond.conf

AUTHDAEMOND="authdaemond.plain"

Code:

edit /etc/courier-imap/authdaemonrc

authmodulelist="authpam"

```

I had to fabricate those files manually, and place in each the code suggested. (That was likely the first error I made!)

Having setup Sypheed, as best I could, trying both cgmd@localhost.localdomain as well as root@localhost.localdomain, and then composing a message to myself and sending it, results in the message going off and disappearing.  :Sad: 

If I then try to check messages, I get the following error in my terminal:

```
(sylpheed:30142): Sylpheed-CRITICAL **: folderview_check_new_item: assertion `item != NULL' failed

```

What can I do to troubleshoot this?

Anyone with suggestions??

Thanks!

----------

