Posts Tagged ‘debian’

configure mail server EXIM on debian

July 29th, 2011

Configuration

use the command:

dpkg-reconfigure exim4-config

and follow the instructions.

Error handle

If there is an error message saying:

ALERT: exim paniclog /var/log/exim4/paniclog has non-zero size, mail system possibly broken ... failed!
You can fix it by simply removing the log file by:
rm /var/log/exim4/paniclog
And then restart the server:
 /etc/init.d/exim4 restart

set up postfix on debian

July 13th, 2010

Suppose you have 2 sites: aaa.com & bbb.com. And you would like to set aaa.com as a local domain, and bbb.com as a virtual domain. That means emails of user@aaa.com will go to the system user’s personal mail dir while user@bbb.com has no actual corresponding system user. Details about local domain & virtual domain, please see paragraph “Virtual domains versus local domains” at http://workaround.org/ispmail/etch.

part 1: configure local domain aaa.com

  • install postfix
    apt-get install postfix
  • config postfix
    add the domain to config files using psotconf:
    postconf -e "myorigin = aaa.com"

    add hostname:
    postconf -e "myhostname=aaa.com"
  • Reload Postfix Server:
    postfix reload

Now you can try to send a email via telnet.
telnet localhost 25
You should see:

Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.
220 aaa.com ESMTP Postfix (Debian/GNU)

Now send a test mail to yourself:

mail from:<test@testsite.com>
rcpt to: <user@aaa.com>
data
To: user@aaa.com
From: test@testsite.com
Subject: First test mail to yourself
Damn it! It worked! Hahahahaha…
Bye…

End the input with an enter, then a dot “.”, and an enter again.
<enter>
.
<enter>

And then quit:
quit

Now use mail to check your email.

part 2: configure virtual domain bbb.com

  • create a user and take his home dir as the virtual server’s base dir.
    #> groupadd -g 5000 vmail
    #> useradd -g vmail -u 5000 vmail -d /home/vmail -m
  • set the virtual_uid_maps and virtual_gid_maps to these IDs:
    #> postconf -e virtual_uid_maps=static:5000
    #> postconf -e virtual_gid_maps=static:5000
  • add bbb.com as a virtual domain into virtual_mailbox_domains
    #> postconf -e virtual_mailbox_domains=bbb.com
  • set the base dir
    #> postconf -e virtual_mailbox_base=/var/spool/vmail
  • reload postfix
    #> postfix reload;
  • add virtual email addresses
    • tell which file the email addresses are stored in
      #> postconf -e virtual_mailbox_maps=hash:/etc/postfix/vmailhost
    • create the file and add some addresses in there.
      #> vi /etc/postfix/vmailhost
      with content like this:
      service@bbb.com bbb.com/service/
      webmaster@bbb.com bbb.com/webmaster/

      So, the mail files for service will actually be stored in /home/vmail/bbb.com/service, and mail files for webmaster will be in /home/vmail/bbb.com/webmaster
    • Now, map the file into DB
      #> postmap /etc/postfix/vmailhost
  • Probably you also need to create the dirs for these 2 addresses
    mkdir /home/vmail/bbb.com/service/bbc.com
    for service@bbb.com
    #> mkdir /home/vmail/bbb.com/service/bbc.com/service
    #> cd /home/vmail/bbb.com/service/bbc.com/service
    #> mkdir new curr tmp
    And do the same for webmaster@bbb.com
  • change the owner and permissions if you created this folders manually and with ROOT privilege:
    #> chown -R vmail:vmail /home/vmail/bbb.com/
    #> chmod -R 700 /home/vmail/bbb.com/

OK, now you can send mail via telnet to have a test.

part 3: configure alias for service@bbb.com

If you want to forward received mails of service@bbb.com, you can use a alias to forward to your another email address, let’s say service.bbb@gmail.com.

  • tell where is the alias configuration file
    #> postconf -e "alias_maps = hash:/etc/postfix/aliases"
    postfix reload;
  • add forward rules in the file:
    #> vi /etc/postfix/aliases
    with the conetent:
    service@bbb.com service.bbb@gmail.com
    and map it:
    #> postmap /etc/postfix/aliases

Note

  • Every configuration done by postconf, you can actually do it by editing /etc/postfix/main.cf directly.
  • Every time you change mail.cf with command postmap, do not forget to reload postfix with: #> postfix reload.
  • Every time you change a db file, do not forget to re-postmap it with: #> postmap /etc/postfix/xxxxx.
  • If you want to set both sites into virtual server, only set localhost as your destination and both sites into virtual domain.

Important debug method

First, all check the log which should be /var/log/mail.log, no matter you want to find the cause of the failure or to check that your email is sent/received successfully.

Second, use mutt to try to send/receive emails

Important references

domain

———————– v1.1: 27/08/2010 ————————

How to add SASL auth

atually a complete instruction for install postfix on debian
official postfix manual

———————– v1.2: 27/08/2010 ————————

How to set up SPF

http://www.howtoforge.com/postfix_spf

———————– v1.3: 03/09/2010 ————————

How to set up domain keys & dkim

Setting up domain keys with dkfilter:

Note: as the dkfilter author has said, dkfilter is deprecated now and DKIMproxy is recommended.

Follow this link : http://bliki.rimuhosting.com/space/knowledgebase/linux/mail/dkfilter+setup except the settings in file /etc/postfix/master.cf should be:

pickup    fifo  n       -       n       60      1       pickup
    -o content_filter=dksign:[127.0.0.1]:10027

And, you may also need to add these as said in http://jason.long.name/dkfilter/:

#
# modify the default submission service to specify a content filter
# and restrict it to local clients and SASL authenticated clients only
#
submission  inet  n     -       n       -       -       smtpd
    -o smtpd_etrn_restrictions=reject
    -o smtpd_sasl_auth_enable=yes
    -o content_filter=dksign:[127.0.0.1]:10027
    -o receive_override_options=no_address_mappings
    -o smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject

#
# specify the location of the DomainKeys signing filter
#
dksign    unix  -       -       n       -       10      smtp
    -o smtp_send_xforward_command=yes
    -o smtp_discard_ehlo_keywords=8bitmime

#
# service for accepting messages FROM the DomainKeys signing filter
#
127.0.0.1:10028 inet  n  -      n       -       10      smtpd
    -o content_filter=
    -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks
    -o smtpd_helo_restrictions=
    -o smtpd_client_restrictions=
    -o smtpd_sender_restrictions=
    -o smtpd_recipient_restrictions=permit_mynetworks,reject
    -o mynetworks=127.0.0.0/8
    -o smtpd_authorized_xforward_hosts=127.0.0.0/8

How to generate key:

perl -MMIME::Base64 -e 'print encode_base64("cihangcihangpassword");'

How to test:

telnet localhost 25
ehlo localhost
auth plain Y2loYW5nAGNpaGFuZwB4TDM4MjVNdjZ1

Setting up Domain Keys and/or DKIM with DKIMproxy:

didn’t try. see here: Mail-DKIM and DKIMproxy.