Mail

Sending Mail From the Command-Line
Install mailx. Example usage: echo hi|mailx -s'hi' someone@somewhere.com

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  to be forwarded to.

Solution
I install  on , and configure it to forward mail to.

Edit : root= mailhub=server_B

must accept mail from.

Edit  and add   to : mydestination = ... server_B

Test
Enter the following on : sendmail root from: server B hello. ... finish with.

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

 * 1) emerge openssl imap dovecot
 * 2) rc-update add postfix default
 * 3) rc-update add dovecot default

Postfix Configuration
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/ root:              schmid operator:          schmid jakob:             schmid someuser:          someuser@someother.address.com   <- forward to other mail server
 * 1) vim /etc/postfix/main.cf
 * 1) vim /etc/mail/aliases
 * 1) postalias /etc/mail/aliases
 * 2) newaliases

SSL Configuration

 * 1) openssl genrsa -out privkey.pem 2048
 * 2) openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095
 * 3) mv cacert.pem /etc/ssl/certs/
 * 4) mv privkey.pem /etc/ssl/private/

Dovecot Configuration
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
 * 1) vim /etc/dovecot.conf

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