# Email Server. [SOLVED]

## justincataldo

I'm pretty new to the whole Gentoo thing, and what I'd really like to know is the easiest way to set up email on my Gentoo server.

I've got a DSL connection, with a dynamic IP address. Using dyndns.org I have assigned a name to the IP. (me.dyndns.org for example).

I'd like to be able to use a mail client (probably thunderbird) to retrieve the email from my server using IMAP. From my server I want to be able to send email from the command line (eg: mail -s name@me.dyndns.org) or something.

Given this, I have been messing around with sendmail and mail and dovecot and different mtu's and a heap of different configurations, but I've not had much success and I'm rather confused about what I need to do really...

So given the information I've provided, what would be the easier way to set this up? I'm a little confused on exactly what I need to do. Like which things do I need? I gather than I need a mail transfer agent (mta), and a few other things, but I don't really understand how everything is intergrated.

I've heard about people using an IMAP setup using Dovecot and Courier. Most people swear that it is easier to configure than Sendmail. But they are all just and crazy each other to someone who is new to setting up email.  :Rolling Eyes: 

So what are some of the configurations people have running? Which mtu/mta/clients do you have running in conjuction and how did you set them up? I want to be able to send and receive mail externally (over the internet, not just internally).Last edited by justincataldo on Tue Aug 09, 2005 11:22 pm; edited 1 time in total

----------

## splooge

I posted this somewhere earlier:

emerge postfix

/etc/postfix/main.cf -- edit these variables to suit:

myhostname

mydomainname

myorigin

mydestination

mynetworks

and you're done.

I also add this to help fight spam (you don't have to):

smtpd_delay_reject = no

smtpd_hard_error_limit = 2

smtpd_helo_required = yes

smtpd_helo_restrictions =

permit_mynetworks,

reject_invalid_hostname,

reject_unknown_hostname,

reject_non_fqdn_hostname

smtpd_client_restrictions =

reject_unknown_client

smtpd_sender_restrictions =

permit_mynetworks,

permit_sasl_authenticated,

reject_non_fqdn_sender,

reject_unknown_sender_domain,

permit

smtpd_recipient_restrictions =

reject_unauth_pipelining,

reject_non_fqdn_recipient,

reject_unknown_recipient_domain,

permit_mynetworks,

permit_sasl_authenticated,

reject_unauth_destination,

reject_rbl_client relays.ordb.org,

reject_rbl_client list.dsbl.org,

reject_rbl_client sbl-xbl.spamhaus.org,

permit

for imap:

emerge courier-imap

it's really that simple

----------

## nevynxxx

Or go to www.gentoo.org then look in the doc's section. There are 3 ro 4 different tutorials depending on the exact config you want.

----------

## JeffBlair

Take a look here.  This sounds like what you want. It will download your mail from your ISP, and store it on your PC. It even has a howto for webmail.

----------

## justincataldo

Well I've done all the splooge's post described. Now what do I do from there? How can I test it?

----------

## splooge

you can test it out using telnet:

#emerge netkit-telnetd

#telnet localhost 25

Make sure you get the 220 response.  If not, you probably need to run newaliases and restart postfix.

If it works, try sending an e-mail to yourname@yourhost.dyndns.org.  It should end up in the /home/yourname/.maildir/new folder, at which point courier can pick it up and serve it to you via imap or pop3.

----------

## justincataldo

Here's what I've done so far:

myhostname = yang.jc.gotdns.org

mydomain = jc.gotdns.org

myorigin = $myhostname

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

mynetworks_style = subnet

Then I ran postfix and tried to telnet to it:

```

yang ~ # /etc/init.d/postfix start

 * Starting postfix ...                                                                                               [ ok ]

yang ~ # telnet localhost 25

Trying 127.0.0.1...

Connected to yang.

Escape character is '^]'.

```

So it looks like that is working...

I then ran courier.

```

yang mail # /etc/init.d/courier-imapd start

 * Starting courier-authlib: authdaemond ...                                                                       [ ok ]

 * Starting courier-imapd ...                                                                                         [ ok ]

yang mail #

```

I emerged mutt ('cause I figured it would be best to get things working with mutt before I complicate things with Thunderbird), then tried to email justin@yang.jc.gotdns.org from the mutt (internally) and also from work (externally), but when I checked the justin account's mutt mailbox it is empty. What else do I need to do? Is my configuration correct? Do I need to edit the /etc/mail/aliases file? When I go into mutt it says /home/justin/.maildir/: no such file or directory (errno = 2). Is that a bad thing?

Do I need to do anything special with my modem configuration? Like forward any ports specifically?

----------

## splooge

You need to run newaliases and restart postfix.  You didn't receive a 220 respons from your e-mail server.  This typically indicates postfix didn't find it's alias database.

It should look like this:

#telnet localhost 25

Trying 127.0.0.1...

Connected to fw.pwned.com.

Escape character is '^]'.

220 mail.pwned.com ESMTP Postfix

.maildir will get created automagically when postfix receives its first e-mail.

----------

## splooge

 *justincataldo wrote:*   

> Do I need to do anything special with my modem configuration? Like forward any ports specifically?

 

If you're using a dsl/cable router, yes, you'll need to forward port 25 into your server.  If your linux box is connected directly to the net you should be fine.

----------

## justincataldo

Ok, well I'm not quite there yet, but I'm close...

Using mutt, I can send and recieve mail internally. I can recieve mail from places on the internet (gmail etc), but can't send mail out to the internet. If I look at the mail queue using Webmin I can see it sitting there, but not being sent. How do I fix this?

And once that is fixed, how do I configure Thunderbird?

----------

## splooge

Your ISP might be blocking port 25 outbound.  See if you can connect to someone elses smtp server.

telnet mail.pwned.com 25

And see if you get a connection

----------

## justincataldo

I tried to telnet to your server from windows, but it said "Could not open connection to the host, on port 25: Connection failed".

From my server:

```

justin@yang ~ $ telnet mail.pwned.com 25

Trying 69.175.14.102...

telnet: Unable to connect to remote host: No route to host

```

I am forwarding port 25 on my DSL modem to port 25 on my server. Is there something else I need to do?

My ISP is Telstra Bigpond (in Australia).

----------

## rex123

A little bit of gratuitous smtp background:

If you want to send mail to someone, it has to end up at their mail server, which is defined in DNS with an mx record. The steps are these:

1) look up the mx record for the domain in dns (take the one with the lowest priority number first)

2) connect to the mail exchanger (mx), port 25

3) send the e-mail using the smtp protocol

What this looks like when you do it manually (sending to [anyone]@microsoft.com):

```
 $ dig mx microsoft.com

[...]

;; QUESTION SECTION:

;microsoft.com.                 IN      MX

;; ANSWER SECTION:

microsoft.com.          1926    IN      MX      10 mailc.microsoft.com.

[...]

;; ADDITIONAL SECTION:

maila.microsoft.com.    3238    IN      A       131.107.3.124

[...]

--- We now know that the server to try is 131.107.3.124

$ telnet 131.107.3.124 25

Trying 131.107.3.124...

Connected to 131.107.3.124.

Escape character is '^]'.

220 IGR-IMC-02.redmond.corp.microsoft.com Microsoft ESMTP MAIL Service, Version: 6.0.3790.1830 ready at  Wed, 6 Jul 2005 02:57:11 -0700

quit [I don't want to actually spam bill]

221 2.0.0 IGR-IMC-02.redmond.corp.microsoft.com Service closing transmission channel

Connection closed by foreign host.

```

2 extra points:

1) All that work is normally done by your own MTA (mail transfer agent), not by you.

2) sometimes you can't connect directly to the MX of the recipient, but you relay via another MX, which is then called a smarthost (I have no idea why; they aren't very smart)

You can forget all that if you like, but I think it's useful to know if you are interested in running your own mail server successfully.

Back to your question. Most likely bigpond is blocking port 25 to any hosts other than their own smarthosts. This is to prevent spam, and is sensible. So you need to tell postfix to send all mail to the bigpond smarthost (don't ask me what it is - their web site will tell you), which will relay it because it trusts you (because you are their customer). I don't know how to do that using postfix, but it can't be all that hard.

If you use Thunderbird, you can send mail directly via the smarthost (set it up as the SMTP server) and not via your local server at all, which might make your life easier. Mutt requires a local MTA because it doesn't know how to do SMTP, but Thunderbird is modelled on Windows-style apps, which don't expect a local MTA.

Your mail server is working fine for incoming SMTP (I just tried it), but you might need to check where it delivers to, and then check that your IMAP server is using the same location.

----------

## splooge

 *justincataldo wrote:*   

> I tried to telnet to your server from windows, but it said "Could not open connection to the host, on port 25: Connection failed".
> 
> From my server:
> 
> ```
> ...

 

Hmm, try a different mail server.  "No route to host" isn't indicative of a blocked outbound port.  I'm looking for something more along the lines of a "Connection refused."  Try:

telnet mail.homestore.com 25

Forwarding port 25 on your dsl router is what gets the mail in.  It has nothing to do with the mail going out.  If outbound 25 is indeed blocked, you'll need to adjust the relayhost setting in main.cf accordingly to use your isp's mta.

----------

## justincataldo

Same thing on Windows "Could not open connection to the host, on port 25: Connection failed").

From Linux:

```

justin@yang ~ $ telnet mail.homestore.com 25

Trying 209.74.97.215...

telnet: Unable to connect to remote host: Connection timed out

```

Although, I did try the following and it worked:

```

yang ~ # telnet mail.bigpond.com 25

Trying 144.140.80.10...

Connected to mail.bigpond.com.

Escape character is '^]'.

220 omta03ps.mx.bigpond.com ESMTP server ready Wed, 6 Jul 2005 15:13:12 +0000

```

----------

## DaveArb

Looking on Google, Telstra started port 25 blocking in April, 2004. You can of course hit their mailserver on port 25, otherwise any email at all would be very difficult. Smarthosting through their mailerver, or convincing them to unblock your port 25 (should be unlikely) are your options as I see them.

Dave

----------

## rex123

Bigpond is clearly blocking port 25 to arbitrary hosts. A quick Google for 'telstra bigpond "port 25" blocked' confirms this.

So set up postfix to use mail.bigpond.com as the smarthost (or relayhost), and you will be fine. Here's the info you need: http://bigpond.custhelp.com/cgi-bin/bigpond.cfg/php/enduser/std_adp.php?p_admin=1&p_faqid=5564&p_created=1081218123

----------

## justincataldo

relayhost = mail-hub.bigpond.net.au seems to do the trick.

I can now send and recieve email internally and externally.  However, when I send mail to an external address it says it came from justin@yang.jc.gotdns.org but if anyone tries to reply it's not going to work.  The reply address needs to be justin@jc.gotdns.org. I don't understand why this is happening. In my main.cf file I have myorigin = $mydomain. But if I go cat /etc/dnsdomainname it spits out jc.gotdns.org. So where the hell is it getting yang.jc.gotdns.org from?

How do I configure thunderbird? At the moment I have got:

Server Type: IMAP Mail Server

Server Name: yang.jc.gotdns.org

Port: 143

Username: justin

When I start it up it asks me for the password for justin@yang.jc.gotdns.org. But when I put it in it says Login to server yang.jc.gotdns.org failed. Is port 143 the correct port? Do I need to change some IMAP configuration somewhere?

----------

## rex123

 *justincataldo wrote:*   

> relayhost = mail-hub.bigpond.net.au seems to do the trick.
> 
> I can now send and recieve email internally and externally.  However, when I send mail to an external address it says it came from justin@yang.jc.gotdns.org but if anyone tries to reply it's not going to work.  The reply address needs to be justin@jc.gotdns.org. I don't understand why this is happening. In my main.cf file I have myorigin = $mydomain. But if I go cat /etc/dnsdomainname it spits out jc.gotdns.org. So where the hell is it getting yang.jc.gotdns.org from?
> 
> 

 

That's your hostname. Your local domain is jc.gotdns.org, and the computer you are using has yang as its unqualified hostname (which is why your bash prompt starts with "yang").

I'm assuming you are using mutt, which would naturally use your username@your hostname as the from address. But you can configure mutt with something like

```
set from="Justin <justin@jc.gotdns.org>"
```

in .muttrc

Or use Thunderbird to send mail, by telling it to use the bigpond smtp server. Thunderbird will use whatever you tell it as the from address.

 *justincataldo wrote:*   

> 
> 
> How do I configure thunderbird? At the moment I have got:
> 
> Server Type: IMAP Mail Server
> ...

 

Sounds like you are connecting to your IMAP server, but the password isn't working. If you're using your shell logon password, it will only work if your IMAP server is configured to use that. So it's probably an IMAP config question... and I don't know what IMAP server you are using. But whatever it is, look for its logs. It should be logging to /var/log/something. Even courier, which I think is terrible at giving useful logging information, should be able to tell you something about a failed logon.

----------

## katsiki

Dear justincataldo:

I would skip installing an MTA until you get more familiar with the other parts of your system, since it sounds like you have a third-party account that provides SMTP.  Give a try to using ssmtp, which is included in the default 2005.0 stage 3 installation.  It will enable your daemons and your human users to send mail through your third-party SMTP server.  To setup for outgoing mail, just configure /etc/ssmtp/ssmtp.conf for your third-party SMTP settings.  Very simple, very secure, and you can postpone getting an MX record, DNS, etc.

It is helpful to emerge mutt into the mix.  Traditionally daemon config files are designed to use a command line such as,

```
mail -s
```

to communicate status and logs.  However the Gentoo mailx package looks stale; and emerging it on my system gave compiler errors.  Like mail, mutt can be invoked from the command line.  Plus humans can use it to send mail and receive POP and IMAP too.

Try this Google:

```
site:forums.gentoo.org ssmtp
```

----------

## rex123

 *katsiki wrote:*   

> Dear justincataldo:
> 
> I would skip installing an MTA until you get more familiar with the other parts of your system, since it sounds like you have a third-party account that provides SMTP [...][/code]

 

Yes, but he's running a mail server for incoming mail (to hisname@hisdynadns.domain). So a proper MTA is required. For sending mail, the local MTA can be missed out altogether by the likes of Thunderbird, which I've been recommending, but mutt (and the like) need to use the local MTA, so it might as well be able to send as well as receive.

----------

## justincataldo

Awesome! Adding set from="Justin <justin@jc.mydomain.org>" to Muttrc works. So now Mutt is completely set up. To send and receive.  :Smile: 

Thunderbird is not playing the game though. I've told it to connect to yang.jc.gotdns.org on port 443 (I know it works 'cause I can telnet to it) and I told it to send outgoing mail to mail-hub.bigpond.net.au on port 25 (which we all know works 'cause we can telnet to it too). Yet, Thunderbird says to me "log in to yang.jc.gotdns.org failed".Last edited by justincataldo on Sun Mar 11, 2007 1:58 pm; edited 1 time in total

----------

## rex123

Port 443 is accepting connections, but the logon is failing. Bear in mind that mutt isn't fetching mail via IMAP, so the fact that mutt is working won't help with thunderbird's IMAP connection.

I would guess that your IMAP server configuration is wrong. Either that or you are entering the wrong password all the time. As I mentioned, the logs should help. If you want more info, you will probably need to say what IMAP server you are trying to run.

----------

## splooge

edit the myorigin line in /etc/postfix/main.cf to say jc.gotdns.org.

----------

## justincataldo

 *splooge wrote:*   

> edit the myorigin line in /etc/postfix/main.cf to say jc.gotdns.org.

 Alright. I've done this. But when I send email it still says the return address is justin@yang.jc.gotdns.org. The return address is only correct when I set it in the Muttrc file (justin@jc.gotdns.org).

I am using courier-imap.

Does anyone know what I need to configure in courier-imapd to allow Thunderbird to log in?

----------

## rex123

 *justincataldo wrote:*   

> Does anyone know what I need to configure in courier-imapd to allow Thunderbird to log in?

 

I'm using a slightly old version of courier-imap, but something like this should work (though it may not exactly be what you want):

- Make sure you have the pam USE flag set (emerge -pv courier-imap to check)

- Make sure that in /etc/courier-imap/imapd you have AUTHMODULES="authdaemon"

- Make sure that in /etc/courier-imap/authdaemonrc you have authmodulelist="authpam" (it doesn't matter if there's a load of other stuff in there)

- Restart courier-imap, and try to log in using your shell username/password. Don't try to use your e-mail address as the username, for example.

If you're not using pam for login, you can probably tweak it to use shadow, by changing authpam to authshadow.

But, honestly, look in the logs. Try something like

```
#cd /var/log

#grep imap * | less
```

----------

## justincataldo

My /etc/courier-imapd/imapd file does not have a AUTHMODULES="authdaemon" option. Should I add one?

The /var/log grep command showed this:

```

messages:Jul  8 23:28:22 yang imapd: Connection, ip=[::ffff:10.0.0.8]

messages:Jul  8 23:28:32 yang imapd: LOGIN FAILED, user=justin, ip=[::ffff:10.0.0.8]

messages:Jul  8 23:28:32 yang imapd: authentication error: Input/output error

messages:Jul  8 23:29:02 yang imapd: Connection, ip=[::ffff:10.0.0.8]

messages:Jul  8 23:29:06 yang imapd: LOGOUT, ip=[::ffff:10.0.0.8]

messages:Jul  8 23:31:54 yang imapd: Connection, ip=[::ffff:10.0.0.8]

messages:Jul  8 23:31:57 yang imapd: LOGIN FAILED, user=justin, ip=[::ffff:10.0.0.8]

messages:Jul  8 23:31:57 yang imapd: authentication error: Input/output error

```

----------

## rex123

We're getting there. Maybe have a look in /var/log/messages (because that's where courier is logging to) and see what context you have. There might be some more information lurking.

If you want a shell command, here's one:

```
grep -C 5 imap /var/log/messages
```

If there's something about mysql or anything like that, then the problem is that courier is trying to do mysql authentication instead of pam authentication. I think that the way this is configured has changed in courier 4, and I'm running 3.0.2 (hence, presumably, the AUTHMODULES difference), so you'll need to work it out. It's possible that re-emerging with different USE flags will fix it if you don't like messing with config files.

----------

## justincataldo

I tried changing the things which were in the authlist parameter and restarting courier-imapd but it made no difference.

Viewing the logs it obviously has issues with MySQL though:

```

Jul  9 18:17:10 yang imapd: Connection, ip=[::ffff:10.0.0.2]

Jul  9 18:17:12 yang authdaemond: failed to connect to mysql server (server=mysql.example.com, userid=admin): Unknown MySQL Server Host 'mysql.example.com' (1)

Jul  9 18:17:12 yang imapd: LOGIN FAILED, user=justin, ip=[::ffff:10.0.0.2]

Jul  9 18:17:12 yang imapd: authentication error: Input/output error

```

I was thinking that dovecot might work, but it requires MySQL as well? Why do these require MySQL anyway? Is it to check for a list of users or something?

Incidentally, I have MySQL installed and working. I use it from within Webmin.

```

yang log # emerge dovecot -pv

These are the packages that I would merge, in order:

Calculating dependencies ...done!

[ebuild  N    ] net-mail/dovecot-0.99.14-r1  -debug -gnutls +ipv6 -ldap -mbox +mysql -nopop3d +pam -postgres -sasl +ssl -vpopmail 850 kB

Total size of downloads: 850 kB

yang log # emerge courier -pv

These are the packages that I would merge, in order:

Calculating dependencies ...done!

[blocks B     ] net-mail/courier-imap (is blocking mail-mta/courier-0.48.1)

[blocks B     ] mail-mta/postfix (is blocking mail-mta/courier-0.48.1)

[ebuild  N    ] app-text/aspell-0.50.5-r4  +gpm 992 kB

[ebuild  N    ] app-dicts/aspell-en-0.51.1  168 kB

[ebuild  N    ] net-nds/portmap-5b-r9  (-selinux) +tcpd 18 kB

[ebuild  N    ] app-admin/fam-2.7.0-r2  294 kB

[ebuild  N    ] mail-mta/courier-0.48.1  +crypt -fax +ipv6 -ldap -mailwrapper +mysql +nls -norewrite +pam -postgres +spell 5,737 kB

[ebuild  N    ] app-crypt/gnupg-1.4.1  -X -bzip2 -caps -curl -ecc -idea -ldap +nls +readline (-selinux) -smartcard +zlib 2,756 kB

Total size of downloads: 9,968 kB

yang log # emerge courier-imap -pv

These are the packages that I would merge, in order:

Calculating dependencies ...done!

[ebuild   R   ] net-mail/courier-imap-4.0.1  +berkdb -debug -fam +gdbm +ipv6 +nls (-selinux) 0 kB

Total size of downloads: 0 kB

yang log #

```

----------

## rex123

You have MySQL installed, but you don't want to use it for authentication to courier. At least, I don't think you do. You want to use the username and password that you use to log on, right? This username/password isn't stored in MySQL, so there's nothing for courier to look up. And courier is configured to look up a MySQL server called mysql.example.com, which is obviously nonsense.

This should work:

edit your package.use file (google for info on how to do this) to remove mysql for courier-authlib. Then emerge courier-authlib again. courier-authlib seems to be the package that manages all courier authentication.

----------

## justincataldo

 *rex123 wrote:*   

> edit your package.use file (google for info on how to do this) to remove mysql for courier-authlib. Then emerge courier-authlib again. courier-authlib seems to be the package that manages all courier authentication.

 

I've just tried this, but it's still not letting me in.

The logs still have the same error:

```

messages:Jul 11 21:52:28 yang imapd: Connection, ip=[::ffff:10.0.0.2]

messages:Jul 11 21:52:32 yang imapd: LOGIN FAILED, user=justin, ip=[::ffff:10.0.0.2]

messages:Jul 11 21:52:40 yang imapd: LOGOUT, ip=[::ffff:10.0.0.2]

messages:Jul 11 21:54:03 yang imapd: Connection, ip=[::ffff:10.0.0.2]

messages:Jul 11 21:54:07 yang imapd: LOGIN FAILED, user=justin, ip=[::ffff:10.0.0.2]

messages:Jul 11 21:54:15 yang imapd: LOGOUT, ip=[::ffff:10.0.0.2]

```

----------

## rex123

What does 

```
emerge -pv courier-authlib
```

 say?

----------

## justincataldo

my /etc/portage/package.use file contains:

```
net-libs/courier-authlib -mysql
```

The command you wrote spits out the following:

```

yang / # emerge -pv courier-authlib

These are the packages that I would merge, in order:

Calculating dependencies ...done!

[ebuild   R   ] net-libs/courier-authlib-0.55  +berkdb +crypt -debug +gdbm -ldap -mysql +pam -postgres 0 kB

Total size of downloads: 0 kB

```

Would I have any success trying to use horde-imp or would I have the same issue?

----------

## rex123

 *justincataldo wrote:*   

> Would I have any success trying to use horde-imp or would I have the same issue?

 

You might, but your problem doesn't lie with courier-imap: it's a configuration error. If you have configuration errors that you can't fix using one bit of software, you probably will with another. If you find that some other imap server works fine first time, that's just a fluke if you don't know how to configure it.

You could try having a look at this thread, as well: https://forums.gentoo.org/viewtopic-t-349638-highlight-courierauthlib.html

----------

## justincataldo

Yaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay! It works!

I removed the mysql option from both the /etc/courier and /etc/courier-imap locations and now it works!

Ahhhhhh sweeeeet success!  :Very Happy: 

Thanks very much for your help everyone!

----------

