# How do I setup a mailserver...my very first time

## rajl

Ok,

     So my small orginzation decided to move from a Windows environment to a linux environment because of licensing issues, and choose to use gentoo, namely because I'm the only guy there that uses linux and it happens that I use gentoo at home.  They therefore elected me to make the switch.

      This means that we need to use a linux mail server to handle our mail.  I've tried to go through the numerous documentations out there, but I can't make sense of it.  Nothing labels itself as "mail serving software" but as either a Mail Transport Agent (MTA), or a mail retrieval tool, what ever either of those mean.

     So, in short, I have no idea what I need to do.  What packages should I download to setup smtp server, imap server, and pop server.  Is there one package that does all three, or do I need to download three seperate packages.  Which package(s) should I download?  How do I set them up, or where can I find a good tutorial for setting them up?

    Please respond as soon as you can, as time is of the essence.

----------

## guero61

I followed the Desktop Configuration Guide section on this, and it worked perfectly for me, but I'm a single user and I gave 6 other people mail accounts on it.

[edit]

The courier suite may have something for you as well.  2 minutes to initial posting, quick enough?  :Laughing: 

[/edit]

----------

## rajl

I can't believe I missed that guide...it's much friendlier than the others, but i'm still a little lost.  I did an emerge -p postfix and got the following:

Calculating dependencies ...done!

[ebuild  N   ] dev-libs/libpcre-3.9-r1  

[blocks B    ] net-mail/ssmtp ("virtual/mta" from pkg net-mail/postfix-2.0.3)

[ebuild  N   ] net-mail/postfix-2.0.3  

What does that mean?  ssmtp is something that vcron had listed as a depencency, so that's where it came from.

To make the problem easier, if we can just setup mail-forwarding and email lists, my life will be a lot easier and I can setup full fledged smtp and pop and imap at much more leisurely pace.

----------

## guero61

You need to do this:

```

emerge unmerge net-mail/ssmtp

```

Then, just start back where you were.  It'll all work out in the end, believe me.  At least it should...  :Embarassed: 

The net-mail/ssmtp deal is, as I see it, more a stub than anything.  Cron has to have some mail transport to be able to send root notifications of failures, but that's about all it's good for.  It'll only complain in your log files if you don't have a way to send, but you'll be fixing that very soon once you put in postfix.

----------

## caffiend

You need an MTA. I use Exim and have for years, I am quite happy with it. The Exim mailing list is a very good resource, just make sure that you've read the documentation, searched the archives, and have done all you can to decipher any error messages rather than posting something like "What does 'Connection refused' mean?"

The configuration file for Exim is very self-explanatory.

----------

## abhishek

 *guero61 wrote:*   

> You need to do this:
> 
> ```
> 
> emerge unmerge net-mail/ssmtp
> ...

 Yeah it is similar to nbsmtp(and I'm sure there are a few other such programs). It just hands the stuff off to an smtp server.

----------

## rsk

I don't think anyone quite answered the original question of "whats what" yet... and I say this because I'm attemping this same thing as we speak  :Smile: 

So far I think I understand that you at least need a mail service running to GET mail for all mail comming to users @domain.com (Where domain.com is whatever domain you are setting mail up for). And then you also need something to intercept outgoing mails (smtp) and fire them out onto the network, this would be like Sendmail right?

Assuming this is right (Which I'm sure its not) where do fetchmail, imap, etc. come into play? How do they all place nice together? Which ones should we use? (specific programs, sendmail, qmail, qpopper, fetchmail, courier (seems the most popular for imap) blah blah).

I need a good jumping off point

----------

## guero61

Actually, if you'll follow the above link and use the directions provided, you'll get a nice setup.  Here's kinda what you're asking:

1.  Receiving mail:  postfix, sendmail, qmail, etc are set up to listen for incoming mail to the box from outside.  You need one if you intend the box to receive mail from outside the machine.

2.  Reading mail:  mutt, pine, kmail, etc are just that - mail clients on individual machines that can be used to read the mail that's come in.

3.  Sending mail:  postfix, sendmail, qmail, courier, etc sit on the machine, listening for internal or external [port 25] requests to send an email out.  Once authenticated, (hopefully!!) the program shoots the mail out the wire to the recipient server.

4.  Other transports:  IMAP, fetchmail, qpopper, etc are programs, protocols, and otherwise designed to aid in remote mail checking and sending.  IMAP and POP3 are the two main mailcheck protocols, with IMAP supporting SSL so you can have a secure connection.  Fetchmail, qpopper, and others (not sure on qpopper, if it's a server or a receiver) use the IMAP and POP3 protocols to 'fetch' mail from remote servers (or not, it can be local).

What you need for a full-fledged mail system (as outlined in the guide):

1.  Receiving.  I use postfix

2.  Sending.  Again, postfix for me

3.  Remote Protocol.  I use IMAP over SSL to connect to the machine.

4.  Client.  CLI, I use mutt, GUI I use kmail

I cannot stress enough -- if you don't know a great deal about setting up mail services, follow the guide, and go from there.  It will satisfy most small to medium-sized needs.  If it does not do what you need, at least you have a starting point to build upon.  I cannot throw all my mail experience into one post, but the guide will give you the jumping-off point you're looking for.

I do not profess to be an expert in this area, but I hope to have shed some bit of light.

----------

## rajl

ok, so I've followed the guide and am at a point where I'm scratching my head, and want to solve this before I proceded

I followed all the gentoo guides to mail, and appear to have postmail setup correctly according to the guide.  So I then run mutt.  I send an email to myself.  I then run mutt and find that it doesn't show any new email.  I know the email has been received though, because the test messages keep sitting there in the ~/.maildir folder, and I can read through them with less and see that they are my email messages.  The problem is that mutt doesn't want to see the messages in my ~/.maildir folders.  How do I get my email programs to read the emails BEFORE I go on any further?

----------

## guero61

Did you go through the whole rigamarole of "/root/.maildir does not exist"?  The same should happen for ~/.maildir, if postfix is running when you type "mutt -x root" or "mutt -x $USER"

----------

## rajl

yes, I did....that was how /maildir wass created

----------

## guero61

Wow.  I'm at a loss; I followed the guide precisely, and it worked perfectly.  You followed it precisely, and it almost works perfectly.  *sigh*, this question may be out of my league.

My only thought is this: add courier, postfix, and imap to your USE flags.  Re-merge mutt and see if that changes things.  If not...  I'm not sure.

----------

## rsk

I followed it exactly and can't get shit to work. I can't send mail locally or remotely (even though I've completely opened up the trusted relay domains and all that business) and I can't recieve mail locally or remotely, with either pop3 or imap.

I get "relay access denied" or something to that extent when trying to send mail locally, BUT I can telnet into the SMTP server on port 25... I'm using Pine to try and send the mail.

I'm getting ready to unmerge it and remerge it and just try again... or hang myself.

----------

## guero61

Some rhetorical questions -- just for troubleshooting, not answering.

1.  Have you restarted postfix since you made the changes?

2.  Are you using name-resolution to hook to you box?  If so, is it going outside your network first, then coming back in?

3.  What setup are you using for trusting?  If you're on a private network, I highly recommend using the "192.168.x.0/2x (24 for whole network, and so on).  

Post your postfix config file, less comments, and I'll see (or someone else will) what we can figure out.

----------

## rsk

 *Quote:*   

> 
> 
> 1. Have you restarted postfix since you made the changes? 
> 
> 

 

Yes

 *Quote:*   

> 
> 
> 2. Are you using name-resolution to hook to you box? If so, is it going outside your network first, then coming back in? 
> 
> 

 

Yes using naming, and yes going outside and comming back in (going out to my ISPs DNS then comming back in)

 *Quote:*   

> 
> 
> 3. What setup are you using for trusting? If you're on a private network, I highly recommend using the "192.168.x.0/2x (24 for whole network, and so on). 
> 
> 

 

I'm using that entry as well as 127.0.0.0/24

How do I post my config without comment lines? (I hope its not a matter of selecting and cutting all the comments... anyone have a fancy cat/grep thing to do it?)

Thanks!

----------

## rsk

Heyyyy a new development...

I just did a "rkalla@localhost" to "rkalla@localhost" (rkalla is my login name) and it sent!

The problem seems to be that I don't get the email though... how do you force Pine to fetch new mail? Or does pine just read whats delivered to your mailDir?

----------

## rsk

Ok update, I added the external IP address of the server I setup postfix on (since it goes out to DNS and back in) and now I can send mail successfully!

I just checked, and it seems that mail is recieved successfully as well, EXCEPT pine doesn't see it. I've enabled the incomming mail check in pine and set the incomming mail folder to be .maildir/new yet pine still doesn't see anything.

Any ideas?

----------

## rsk

ok it seems I need to emerge pine-maildir first, THEN those settings I was making might work.

I'll keep everyone posted

----------

## guero61

You got it all -- sorry, I was at class.

If you run your own private (I'm assuming 192.168.x.x) network, the optimally secure setup is to not allow forwarding from outside that 192 net; as you have it set up now, unless you have an authenticated SMTP setup (which I doubt you do at the moment), you have an open relay.

Pine does not do live updating -- that's what pine_maildir is for, and it works fine, as far as I can see from your post!    :Surprised: 

I would strongly suggest setting up an /etc/hosts entry in your client box for your DNS name -- not pointing to your external IP, but your internal one.  That would provide the greatest security.  If you can't do that, then tne next best [probably better] thing is to set up an MTA on your local box and leave forwarding completely off of the external server.

To post any file less config lines, do this:

```

cat $FILE | grep -v /^#/

```

That will not eliminate EOL comments #like this

----------

## rsk

hey that HOSTS idea was a great one! I'll do that now and keep things secure, thanks!

----------

## rsk

ok so now everything is wokring, and I would just like to say that pine does NOT support maildir.

Some of you might say "yes it does", and to that I'll say that after hunting around the forums and news groups for over 2 hours, I've come to the conclusion that there have been NUMEROUS patches to support maildir, some worked, some didn't, but none of them were really official it seemed.

Anyway I just unmerged pine and gave up on it, got onto my windows machine and setup an account with outlook, and walla everything works perfectly. So blech to pine!

----------

## rajl

so what email clients do support ~/.maildir?   Pine won't, and mutt doesn't like it either.  The emails keep showing up in the ~/.maildir/new as individual textfiles, but pine and mutt refuse to read them.  I've done the whole unmerge, remerge with new use flags deal, but that didn't work.  I really want to know how to fix the problem, short of starting over from scratch entirely and preying for it to be ok.

----------

## guero61

This is beyond me -- anyone please help?  Mutt worked the first time for me, which is just really strange.  All I did was follow the guide.  Help?

----------

## rsk

rajl, mutt supposidly has native "maildir" support, where as Pine's support is hacky... is it possible that you were overlooking a config setting in mutt? I've never used it.

I just ended up using the server as a mail server, and I use clients on separate machines (great solution hu?)  :Smile: 

----------

## rajl

i'm mainly using the box as a server anyway (see my post at the top), so I tested it out with some remote clientes logging in through imap, and it seems to work fine.

My only complaint right now is with postfix.  Two things:

a) I can receive emails at "user@mybusiness.org" but I can only send out emails with "user@fully.qualified.hostname.mybusiness.org", which for cosmetic and business reasons I'd rather shrink down to "user@mybusiness.org" for both sending and receiving.

b) email accounts don't work until after I've sent them an email, so that postfix goes in and automatically sets up their directories.  Does it have to be this way?  This isn't nearly as critical as above.

----------

## guero61

a)  Change your smtpd_banner as shown:

```

smtpd_banner = $myhostname ESMTP $mail_name

-to-

smtpd_banner = $mydomain ESMTP $mail_name

```

This may not do exactly what you want, but I'm certain there's a way to change things in main.cf; it'll just take some digging around.  That, and your trust rules may be limiting you to that extended name.

b)  For each user, either send them an email or execute the following:

```

mkdir -p ~$USER/.maildir/tmp

mkdir -p ~$USER/.maildir/new

mkdir -p ~$USER/.maildir/cur

```

----------

## rajl

can you explain the smtpd_banner thing you're talking about?  While I've come along way in the world of mail servers, that went way over my head.  How will that fix my problem?  Is it a permanent of temporary fix?  how would having my trusted network parameters be too tight affect the outgoing email address?

by the way, I figured out why mutt wasn't working..I had both the maildir and mbox use flags set, and the mutt ebuild won't wupport both at the same time.  having "maildir -mbox" solved my problems with mutt

----------

## guero61

If you edit /etc/postfix/main.cf, there is a variable called smtpd_banner that you can change.  I'm not sure if that will change the outgoing hostname, but it should.  If it doesn't, we'll try something else.

Gotcha on the USE flags; I have to constantly watch to make sure I don't have conflicting ones!

----------

## guero61

Just looking, you may want to change myorigin instead of smtpd_banner.

----------

## rajl

changing smtpd_banner didnt'  help...I already have my origin set, but that hasn't seemed to do much.   I set myorigin to several values, includeing $myhostname, $mydomain, and I even tried to hardcode the value that I want into it.  the thing that gets me is that it uses not just the fully qualified hostname, but it uses the WRONG fully qualified hostname.  the computer has two, one provided to use by our isp that is just a generic, uninteresting one they assigned us, and then the name we registered for ourselves.  It's using the hostname our isp gave us, and not the one we registered, even though I set /etc/hostname to be that of our name we registerd and paid for.

----------

## rajl

I know that it's a minor problem, but fixing the whole hostname thing is really my last step to having a fullly functioning email server.  Any help from anyone in resolving this last issue would be greatly appreciated.

----------

## rajl

this other thread in the forum here at https://forums.gentoo.org/viewtopic.php?p=280998#280998

seems to be addressing the problem I have.  Only, when I followed the directions given, nothing happened.  Perhaps he left out a step, or else he has something else configured that I don't know about, like another cf file based on teh sample one?

I'm rather new at postfix, so I couldn't say.  As I said, all help on my issue of making my email addresses work is greatly appreciated.

----------

## guero61

Working on it...

You know you can tell it what myhostname and mydomain are -- just say "myhostname=xxxx" and so on.

Also, it couldn't hurt to make an entry in /etc/hosts to keep it from picking up your ISP's name.

----------

## rajl

my hostname and domain names were already hardwired into main.cf

I put a new entry into my hosts file, linking my static ip to the hostname I registered for, and then reloaded/restarted postfix...didn't seem to work with the test emails I sent.  The from: field still reads user@ugly.hostname.from.my.isp

I also tried the additional steps listed in the other thread after I posted, and they didn't work either.  Sender canonical doesn't seem to work either so far.

----------

## guero61

1.  Are you still in CLI (command line interface)?

2.  Are you running above client from a remote machine or the actual server?

----------

## rajl

1)  I'm sending my emails from the cli using mutt

2)  Mutt is being used on the local machine that postfix is installed on

----------

## guero61

I'm on a windows box right now; Senior Project goes down the pipes if I don't work on it.

Looking at the manpages for muttrc, you can do one of three things --

1.  Set the EMAIL shell variable for the user to the desired address (I'm thinking /etc/profile

2.  Set the $HOME/.muttrc "from" variable.

3.  Use a remote SMTP client and tell it to set the "FROM".

Of the three, #1 seems to address the problem sufficiently.  I just tested, set EMAIL="randy@chiggabiggafigga.net", sent myself an email, and behold, "randy@chiggabiggafigga.net" knows who I am!  A word of caution -- I do not recommend having your clients telnet/ssh in and use mutt directly on the box.  Too many security risks.  Make them use a remote client like kmail, sylpheed, or any number of excellent mail clients.  Plus, the client will take care of all this wrong name nonsense -- it'll set the FROM field to whatever the heck you please.

Add to /etc/profile

```

export EMAIL="${USER}@$(hostname)"

```

----------

## rajl

AHA!!!!  Solved.  The syntax in my sender_canonical file was wrong because I interpreted it incorrectly.  I now have a working mail server setup for my organization.  Thank you all so very much.  You have been most helpful, especially guero61, who's patience and perserverance leave me and my orginization in great debt to.  Now to just get mailman up and running and my firewall rulesets all worked out.  But that is another task, and possibly other threads to start.

----------

## guero61

You're welcome -- it only took us four days!   :Rolling Eyes:   I'll work more on my speed now.    :Very Happy: 

----------

