Blackhole email address

A black hole e-mail address is an e-mail address which is valid (messages sent to it will not generate errors), but to which all messages sent are automatically deleted, and never stored or seen by humans. These addresses are often used as return addresses for automated e-mails (wikipedia).

For backing up and restore data Elasticsearch have feature for that is a snapshot.

Target Audience Document Owner Subject Repository
System Administrator Alex Manroe create blackhole for Mail server

This Technical document contains for create black hole e-mail address for testing development.

Todo

  • Install Postfix and Dovecot.
  • Configure Postfix and Dovecot.
  • Testing E-mail function.
  • Install Webserver and php5-fpm.
  • Install Mysql-server.
  • Install Roundcube.

Install Postfix and Dovecot

Install using apt-get for quick.

root@b6607897828a:~# apt-get install -y --no-install-recommends postfix postfix-pcre dovecot-mysql dovecot-core dovecot-pop3d dovecot-imapd mailutils procmail

wait until installing finish.

Configure Postfix and Dovecot

After installing package for postfix and dovecot now we must reconfigure postfix.

Configure Postfix

**should be like below**
root@b6607897828a:~# vi /etc/postfix/main.cnf
# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Development Mail Server)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = mail.domain.cool

alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
virtual_alias_maps = pcre:/etc/postfix/virtual

mydestination = localhost.localdomain, , localhost, mail.domain.cool
relayhost =
mynetworks = 0.0.0.0/0 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 172.17.0.0/24 192.168.0.0/24
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
myorigin = /etc/mailname
inet_protocols = all

now we must add devnull: /dev/null new alias for postfix.

root@b6607897828a:~# vi /etc/aliases
**see like this**
# See man 5 aliases for format
postmaster:    root
devnull: /dev/null

after that create virtual_alias_maps.

root@b6607897828a:~# vi /etc/postfix/virtual
**see like this**
/no-reply@.*/ devnull@localhost
/.*@.*/ git

thats every send email using no-reply will redirect to devnull@localhost or whatever email send will redirect to mail git (user git so it’s must be adduser git first).

now after virtual maps create we must run postmap command to create postmap db.

root@b6607897828a:~# postmap /etc/postfix/virtual

let’s start postfix.

root@b6607897828a:~# /etc/init.d/postfix start

Configure Dovecot

**should be like below**
root@b6607897828a:~# vi /etc/dovecot/dovecot.conf
protocols = pop3 imap
mail_location = mbox:~/mail:INBOX=/var/spool/mail/%u
disable_plaintext_auth = no
ssl = no

userdb {
  driver = passwd
}
passdb {
  args = %s
  driver = pam
}
protocol pop3 {
     listen = *:110
}
protocol imap {
     listen = *:143
}

Give group mail for this directory /var/mail.

root@b6607897828a:~# chgrp -R mail /var/mail -f

Edit some config file dovecot follow in below.

root@b6607897828a:~# vi /etc/dovecot/conf/10-auth.conf
disable_plaintext_auth = no
auth_cache_size = 0
auth_mechanisms = plain
!include auth-system.conf.ext
root@b6607897828a:~# vi /etc/dovecot/conf/10-master.conf
service imap-login {
  inet_listener imap {
  }
  inet_listener imaps {
  }
}
service pop3-login {
  inet_listener pop3 {
    port = 110
  }
  inet_listener pop3s {
  }
}
service lmtp {
  unix_listener lmtp {
  }
}
service imap {
}
service pop3 {
  process_limit = 1024
}
service auth {
  unix_listener auth-userdb {
  }
}
service auth-worker {
}
service dict {
  unix_listener dict {
  }
}
root@b6607897828a:~# vi /etc/dovecot/conf/auth-system.conf.ext
passdb {
  driver = pam
}
userdb {
  driver = passwd
}

Now we must run dovecot and dovecot doesn’t have init script we need supervisord for manage run init.

root@b6607897828a:~# apt-get install suvervisor
root@b6607897828a:~# vi /etc/supervisor/conf.d/dovecot.conf
[program:dovecot]
command=/usr/sbin/dovecot -c /etc/dovecot/dovecot.conf -F
autorestart=true

save and run suvervisor check dovecot service.

root@b6607897828a:~# /etc/init.d/supervisor start
root@b6607897828a:~# supervisorctl status
dovecot                          RUNNING    pid 5799, uptime 5:20:14

Until here look like good now we must create user git see in /etc/aliases we will redirect all email into user git.

root@b6607897828a:~# useradd -d /home/git -m git -s /bin/bash
root@b6607897828a:~# usermod -aG mail git
root@b6607897828a:~# passwd git <give passwd for we using in Roundcube>

Testing E-mail function

Before testing mail service we must be enable rsyslog for tracking log activity.

root@b6607897828a:~# apt-get install -y rsyslog
root@b6607897828a:~# service rsyslog start

see log in /var/log/syslog.

Test using telnet with port 25.

alex@Alex-Laptop:~$  telnet mail.domain.cool 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 97e02a815796 ESMTP Postfix (Development Mail Server)
HELO localhost                            <enter>
250 97e02a815796
MAIL FROM: no-reply@blblblbl.com          <enter>
250 2.1.0 Ok
RCPT TO: whatever@you.want                <enter>
250 2.1.5 Ok
DATA                                      <enter>
354 End data with <CR><LF>.<CR><LF>
Subject: Testing blackhole                <enter>
From: aque@asdasdasd.com              <enter>
                                          <enter>
This should be arrive in your inbox :)    <enter>
.                                         <enter>
250 2.0.0 Ok: queued as 8093B90
^]                                        <ctrl+], enter>

Install Mysql-server

Install package mysql using apt-get

root@b6607897828a:~# apt-get install -y mysql-server mysql-client
root@b6607897828a:~# mysql -e "create database roundcubemail_db DEFAULT CHARSET utf8; create user 'git'@'%' identified by '${MYPASSWD}'; grant all privileges on roundcubemail_db . * to 'git'@'%'; flush privileges;"

Webserver and php5-fpm

For using interface Iam using webserver so we need apache2 or nginx for this case Iam using apache2.

alex@Alex-Laptop:~$ apt-get isntall -y apache2 libsasl2-modules apache2 php5-fpm php5-curl php5-mcrypt php5-mysql php5-gd php5-cli php5-pear

Edit file /etc/php5/fpm/pool.d/www.conf.

root@b6607897828a:~# vi /etc/php5/fpm/pool.d/www.conf
;listen = /var/run/php5-fpm.sock
listen = 127.0.0.1:9000

Start php service.

root@b6607897828a:~# service php5-fpm start

Create new file virtualhost in apache2.

root@b6607897828a:~# /etc/apache2/sites-available/mail-dom-cool.conf
<VirtualHost *:80>
        ServerName mail.domain.cool
        ServerAdmin devops@domain.cool
        DocumentRoot /var/www/html/roundcubemail
        <Directory /var/www/html/roundcubemail>
          DirectoryIndex index.php index.html
          Options FollowSymlinks
          Require all granted
          AllowOverride None
          RewriteEngine Off
          RewriteRule ^(.*)/$ /$1 [L,R=301]
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteRule ^ index.php [L]
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/mail-domain-cool.error.log
        CustomLog ${APACHE_LOG_DIR}/mail-domain-cool.access.log combined
        ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/roundcubemail/$1
</VirtualHost>

Enable that config and restart apache2.

root@b6607897828a:~# a2ensite mail-dom-cool.conf
root@b6607897828a:~# service apache2 restart

Download and extract roundcubemail.

root@b6607897828a:~# wget https://github.com/roundcube/roundcubemail/releases/download/1.2.4/roundcubemail-1.2.4-complete.tar.gz
root@b6607897828a:~# tar -xvf roundcubemail-1.2.4-complete.tar.gz
root@b6607897828a:~# mv roundcubemail-1.2.4 /var/www/html/roundcubemail

You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.