Haraka is an open source SMTP server written in Node.js which provides extremely high performance coupled with a flexible plugin system allowing Javascript programmers full access to change the behaviour of the server.
In Web hosting industry dominated by Cpanel, Haraka can co-exist with Exim and can be used as an alternative mail server for clients with large mailing lists. Haraka consumes negligible memory thereby easing the job off Exim which can cater to normal clients hosted on a cPanel server.

Here we guide to configure Haraka as outgoing mail server only. If you want to accept emails and deliver it locally, please refer the official docs.

1. Install Node.js binary (http://nodejs.org/download/)
++++++++++++++++++++++++++++++++++++++++

# cd /usr/local/src/
# wget http://nodejs.org/dist/v0.10.28/node-v0.10.28-linux-x64.tar.gz
# tar zxvf node-v0.10.28-linux-x64.tar.gz
# mv node-v0.10.28-linux-x64 /usr/local/node
# chown -R root:root /usr/local/node
# ln -s /usr/local/node/bin/node /usr/local/bin/
# ln -s /usr/local/node/bin/npm /usr/local/bin/

2. Install git and Haraka
++++++++++++++++++

# yum install git -y
# cd /usr/local/
# git clone https://github.com/baudehlo/Haraka.git
# mv Haraka haraka
# cd haraka
# npm install

3. Create symlinks once the installation is complete
+++++++++++++++++++++++++++++++++++++++

# ln -s /usr/local/haraka/bin/haraka /usr/local/bin/

4. Also copy over the start-up script
++++++++++++++++++++++++++

# cp /usr/local/haraka/contrib/haraka.init /etc/init.d/haraka
# chmod 755 /etc/init.d/haraka

5. Initialize Haraka config directory
+++++++++++++++++++++++++++

# haraka -i /etc/haraka/

6. make changes to config files
++++++++++++++++++++++

vi /etc/haraka/config/smtp.ini:

; address to listen on (default: all IPv6 and IPv4 addresses, port 25)
; use “[::0]:25” to listen on IPv6 and IPv4 (not all OSes)
;listen=[::0]:25
listen=127.0.0.1:587

; Note you can listen on multiple IPs/ports using commas:
;listen=127.0.0.1:2529,127.0.0.2:2529,127.0.0.3:2530

; public IP address (default: none)
; If your machine is behind a NAT, some plugins (SPF, GeoIP) gain features
; if they know the servers public IP. If ‘stun’ is installed, Haraka will
; try to figure it out. If that doesn’t work, set it here.
;public_ip=N.N.N.N

; Time in seconds to let sockets be idle with no activity
;inactivity_timeout=300

; Drop privileges to this user/group
user=mail
group=mail

; Don’t stop Haraka if plugins fail to compile
;ignore_bad_plugins=0

; Run using cluster to fork multiple backend processes
;nodes=cpus

; Daemonize
daemonize=true
daemon_log_file=/var/log/haraka.log
daemon_pid_file=/var/run/haraka.pid

; Spooling
; Save memory by spooling large messages to disk
;spool_dir=/var/spool/haraka
; Specify -1 to never spool to disk
; Specify 0 to always spool to disk
; Otherwise specify a size in bytes, once reached the
; message will be spooled to disk to save memory.
;spool_after=

vi /etc/haraka/config/plugins:

# default list of plugins

# Log to syslog (disabled by default, see docs)
# log.syslog

# control which IPs, rDNS hostnames, HELO hostnames, MAIL FROM addresses, and
# RCPT TO address you accept mail from. See ‘haraka -h access’.
#access

# block mails from known bad hosts (see config/dnsbl.zones for the DNS zones queried)
#dnsbl

# Check mail headers are valid
#data.headers

# block mail from some known bad HELOs – see config/helo.checks.ini for configuration
#helo.checks

# see ‘haraka -h tls’ for config instructions before enabling!
# tls

# Only accept mail where the MAIL FROM domain is resolvable to an MX record
#mail_from.is_resolvable

# Disconnect client if they spew bad SMTP commands at us
#max_unrecognized_commands

# Only accept mail for your personal list of hosts. Edit config/host_list
# NOTE: THIS IS REQUIRED for inbound email.
#rcpt_to.in_host_list

# Queue mail via smtp – see config/smtp_forward.ini for where your mail goes
#queue/smtp_forward

auth/flat_file

vi /etc/haraka/config/auth_flat_file.ini:

[core]
methods=LOGIN,CRAM-MD5

[users]
emailuser=mystrongpassword

vi /etc/sysconfig/haraka:

exec=/usr/local/bin/haraka
config=/etc/haraka/config/smtp.ini
max_open_files=65535

7. Fix permissions:
++++++++++++++

# chown -R mail:mail /etc/haraka/

8. Configure chkconfig:
+++++++++++++++++

# chkconfig –add haraka
# chkconfig haraka on

9. And finally.., start Haraka
+++++++++++++++++++++

# service haraka start

In case haraka failed to start for any reason, check its log file at /var/log/haraka.log.

[root@localhost ~]# service haraka start
Starting haraka: /usr/bin/env: node: No such file or directory
[FAILED]

If you encounter the following error while starting Haraka:

.. then edit /usr/local/haraka/bin/haraka, and modify its first line to:

#!/usr/bin/env /usr/local/bin/node

.. and Haraka will start fine:

[root@localhost ~]# service haraka start
Starting haraka: [ OK ]

Now that Haraka is up and running, use the following settings to send email:

SMTP Server: 127.0.0.1
Port: 587
SSL/TLS: None
SMTP Username: emailuser
SMTP Password: password

On a cPanel server, run Haraka on another port and use it as outgoing email server for bulk mailing/newsletter tasks and spare Exim from the pain!

Leave a Reply

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