Mail

From Schmid.wiki
(Redirected from Setting Up A Mail Server)
Jump to: navigation, search

Contents

Sending Mail From the Command-Line

Install mailx. Example usage:

echo hi|mailx -s'hi' someone@somewhere.com

Multi-Server Mail Setup

Problem

I have two servers in a setup:

server_A - the mail server running Postfix
server_B - another server

I would like the internal mail of server_B to be forwarded to server_A.

Solution

I install ssmtp on server_B, and configure it to forward mail to server_A.

Edit /etc/ssmtp.conf:

root=
mailhub=server_B

server_A must accept mail from server_B.

Edit /etc/postfix/main.cf and add server_B to mydestination:

mydestination = ... server_B

Test

Enter the following on server_B:

sendmail root
from: server B

hello.

... finish with CTRL+D.

Choices

  • I selected Postfix as my mail server, as it seems to be the standard.
  • I will try Dovecot as my IMAP server, as the authors claim that it is small, simple and secure. I didn't use courier-imap, as it seemed very large.
  • I will only use IMAPS with SSL encryption, as plaintext passwords are evil and must die.

Prerequisites

My TDC ADSL connection blocks port 25, but the TDC website stated:

For at forhindre misbrug af mailserveren, er tcp/25 (mailserver-porten) blokeret i TDC' s router, og derfor skal man i DNS sætte en sekundær mailserver (backup-mx.post.tele.dk) ind. Dette gøres som følger:
mail.domaene.dk. IN A x.x.x.x
domaene.dk. IN MX 10 mail.domaene.dk
domaene.dk. IN MX 20 backup-mx.post.tele.dk
Efter TDC har lukket for port 25 - med undtagelse af adgangen til TDC's egen mailserver - skal du ændre opsætningen af din mailserver til at bruge smart host (hedder også relay host). Du skal bruge smtp.mail.dk som smart host.
I postfix gøres dette for eksempel ved at indsætte følgende linie i /etc/postfix/main.cf: relayhost=smtp.mail.dk

I set up my DNS to

mail.schmid.dk IN A [IP]
schmid.dk IN MX 10 mail.schmid.dk
schmid.dk IN MX 20 backup-mx.post.tele.dk

I also had to forward port 25 (SMTP - is forwarded from backup-mx.post.tele.dk) and port 993 (secure imap) to my server in my router setup.

Installation

# emerge openssl imap dovecot
# rc-update add postfix default
# rc-update add dovecot default

Postfix Configuration

# vim /etc/postfix/main.cf
myhostname = schmid.dk                      <- this determines the hostname accepted by
mydomain = schmid.dk                           the mail server, e.g. you can't mail to
myorigin = $mydomain                           schmid@mail.schmid.dk ...
mydestination = $myhostname, mail.$mydomain, localhost <- ... unless you specify it here!
relayhost = smtp.mail.dk                    <- this is the TDC requirement
alias_database = hash:/etc/mail/aliases     <- this is correct. the '.db'-extension is added
alias_maps = hash:/etc/mail/aliases            by postfix
home_mailbox = .maildir/
# vim /etc/mail/aliases
root:               schmid
operator:           schmid
jakob:              schmid
someuser:           someuser@someother.address.com   <- forward to other mail server
# postalias /etc/mail/aliases
# newaliases

SSL Configuration

# openssl genrsa -out privkey.pem 2048
# openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095
# mv cacert.pem /etc/ssl/certs/
# mv privkey.pem /etc/ssl/private/

Dovecot Configuration

# vim /etc/dovecot.conf
protocols = imaps
ssl_cert_file = /etc/ssl/certs/dovecot.pem
ssl_key_file = /etc/ssl/private/dovecot.pem
default_mail_env = maildir:%h/.maildir
auth = default
auth_mechanisms = plain  <- we are already using SSL encryption when logging, so this is OK
auth_userdb = passwd     <- users in /etc/passwd
auth_passdb = shadow     <- passwords in /etc/shadow

Example IMAP Client (Thunderbird) Configuration

Server Name: mail.schmid.dk       Port: 993
User Name: schmid
[x] use secure connection (SSL)
[ ] use secure authentification

References

Personal tools