1) a linux server ( obviously lol ), i have used centos as a os, so i suggest you to with it also, you can buy either vps either dedicated it does not really matter, we don't need some killing machine for this, postfix will not take a lot of resources, but i do recommend to buy at last 512 mb of ram and 20 gb of hdd. you need to buy a vps with many ip addresses, nowadays, ips become expensive and hard to get, you need to fill stupid justification and other stuff to get a lot of ips, but you can still find a providers which won't ask you for that.

here is one good hoster : vps hosting by host1plus ? great performance and great price

they do allow mass mailing, however, they are not saying they allow spam, but since they can't prove do you really have opt-in lists or now, just make sure to make your emails looks legit with opt-out link, some fake company info and make them looks good and not spam like with just a banner image inside lol.

they are hosted in germany and price per ip is 2$, you can find them cheaper, but these guys are quality and their tos allow mass mailing, so it's up on you where are you going to buy vps.

if you are going to spend some time on google you will also find very cheap vps's which comes with 4 or even 8 ip's by default, they are also good solution.

but i highly recommend you to buy at last 50 ip's, that will increase your inbox ratio a lot and won't lead your ips to blacklists fast. you will get blacklisted, that's a matter of time, but - more ips - more time without blacklisting. if you can afford your self 200 ips and if you will send only 100 emails per day per ip ( 20000 / day ), you won't get blacklisted ever.

also at the end of this topic i will explain how to get whitelisted on some isp's, mail providers and spam filters.

1 install postfix

this tutorial is for debian, everything is same like with other linuxes, just don't use sudo command .


you will be shocked at how simple it is to install the postfix mail server. all you have to do is follow these steps:

1) open up a terminal window (or, if you are using a gui-less server just log in).

2) issue the command sudo apt-get install postfix.

that's it! of course, depending upon the current state of your distribution, the installation may or may not have to install some dependencies. but this will happen automatically for you. the installation will also automatically start the postfix daemon for you. so as soon as installation is complete you can test to make sure you can connect to your postfix server with the command:

telnet localhost 25

you should see something like this:

connected to www.mymail.com.
escape character is '^]'.
220 localhost.localdomain esmtp postfix (ubuntu)

now you might want to first make sure you can also connect to your domain in the same way with the command:

telnet www.mymail.com 25

of course you will use your own fdqn in the above command (instead of mymail.com). hopefully you will see the same output you did when you used localhost. if not, you will have to check to make sure your domain is pointing to your server or that port 25 traffic can get to your server from your router, switch, or firewall. those issues are beyond the scope of this article however.

now it is time to start configuration.

configuring postfix

the postfix mail server has one main configuration file /etc/postfix/main.cf. this is where you will do the bulk of your configurations. open this file up in your favorite text editor (mine is nano) and look for the following section:

myhostname =
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination =
relayhost =
mynetworks =
mailbox_command = procmail -a "$extension"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all

this is the section of the configuration file you must focus on. and, believe it or not, there isn't much to do. below are the sections you need to configure:

myhostname: this is the hostname of your machine. but don't put the full hostname. if your machine hostname is mail.mydomain.com you will only use mydomain.

mydestination: this parameter specifies what destinations this machine will deliver locally. the default is:

mydestination = $myhostname localhost.$mydomain localhost

you could also use something like what i have used in the past (for simplicity's sake):

mydomain.com mydomain localhost.localdomain localhost

this call is up to you. either way will work; but the latter line will help to avoid mailloops.

mynetworks: this line is a bit trickier. this entry will define authorized destinations that mail can be relayed from. you would think that adding your subnet here would work. sometimes that is the case; sometimes not. you could go with a mynetworks entry that looks like:

mynetworks =

the above entry is a safe entry and defines local machines only.

you could also have an entry that looks like:

mynetworks =

the above entry would authorize local machines and your internal network addresses.

i have found, however, that the above entries will cause problems with relaying due to constantly changing dhcp addresses. because of this i have used the following, specialized entry which will avoid this issue:

mynetworks = [::ffff:]/104 [::1]/128

now, if your mail server serves up mail to your entire domain, you will need to add another entry to that section above. that entry is:

mydomain = mydomain.com

again, as in all configurations above, the mydomain.com will be substituted with your real domain.

now, save that configuration file and restart your mail server with the command:

sudo /etc/init.d/postfix reload

your mail server should be up and running.


since this is a linux mail server, you will need to make sure you have a user name that corresponds with every email address you need. if your server has a gui you can just use the gui tool for this. if your server is a gui-less server you can create users with the command:

sudo useradd -m username

where username is the actual name of the user. the next step is to give the username a password with the command:

sudo passwd username

again, where username is the actual username. you will be prompted to enter the new password twice.

2) set up dkim on postfix with dkim-milter (centos 5.2)

this howto has been superseded by top***.za.net :: setup dkim on postfix with opendkim
dkim is an authentication framework which stores public-keys in dns and digitally signs emails on a domain basis. it was created as a result of merging yahoo's domainkeys and cisco's identified internet mail specification. it is defined in rfc 4871.

we will be using the milter implementation of dkim about dkim - sendmail.com on centos 5.2.

i provide centos rpms for dkim-milter at index of /oss/ so we will install the latest version.

install the rpm, ( 32bit and 64bit intel supported )
# wget http://www.top***-software.com/oss/r...re.com_key.txt
# rpm --import andrew_top***-software.com_key.txt
# http://www.top***-software.com/oss/dkim-milter/dkim-milter-2.8.2-0.$(uname -i).rpm

generate the keys
# sh /usr/share/doc/dkim-milter-2.8.2/dkim-genkey.sh -r -d <domain_name>

replace <domain_name> with the domain name you will be signing the mail for. the command will create two files.

default.txt - contains the public key you publish via dns
default.private - the private key you use for signing your email
move the private key to the dkim-milter directory and secure it.

# mv default.private /etc/mail/dkim/default.key.pem
# chmod 600 /etc/mail/dkim/default.key.pem
# chown dkim-milt.dkim-milt /etc/mail/dkim/default.key.pem

dns setup
you need to publish your public key via dns, client servers use this key to verify your signed email. the contents of default.txt is the line you need to add to your zone file a sample, is below

default._domainkey in txt "v=dkim1; g=*; k=rsa; p=migfma0gcsqgsib3dqebaquaa4gnadcbiqkbgqdg81cnnvol wwfhenozenjknliktb3dnb5kuc8/zvht/s8sqnx+ygz/kg7kous0by8ciddvwn3elvrvq6jhz/hcvpu5dxcac5owlbf/gx5tvanjf1vsl8zbetxquvhyjqpmfh3vw37m/mxptgmdl+zjvw+ckpuci8bjd03iw2l1cwidaqab"

; ----- dkim default for top***-software.com
also add this to your zone file.

_ssp._domainkey in txt "t=y; dkim=unknown"

create the file /etc/sysconfig/dkim-milter with the contents below overwriting the existing sample file that was installed by the rpm, make sure you set the signing_domain variable to the domain or domains you will be signing mail for.
port="inet:[email protected]"

extra_args="-h -l -d"

configure postfix
you need to add the following options to the postfix main.cf file to enable it to use the milter.

smtpd_milters = inet:localhost:20209
non_smtpd_milters = inet:localhost:20209
append the dkim-milter options to the existing milters if you have other milters already configured.

start dkim-milter and restart postfix

# service dkim-milter start
# service postfix restart

send an email to [email protected] or [email protected], you will receive a response stating if your setup is working correctly. if you have a gmail account you can send an email to that account and look at the message details similar to the picture below, you should see signed-by "your domain" if your setup was done correctly.

3) spf

this tutorial shows how to implement spf (sender policy framework) in a postfix 2.x installation. the sender policy framework is an open standard specifying a technical method to prevent sender address forgery (see spf: introduction). there are lots of spf extensions and patches available for postfix, but most require that you recompile postfix. therefore we will install the postfix-policyd-spf-perl package from openspf.org which is a perl package and can be implemented in existing postfix installations (no postfix compilation required).

i want to say first that this is not the only way of setting up such a system. there are many ways of achieving this goal but this is the way i take. i do not issue any guarantee that this will work for you!

1 preliminary note
i assume that you have already set up a working postfix mail server.

the following procedure is distribution-independent, i.e., it should work on any linux distribution (however, i tested this on debian etch).

2 install required perl modules
the postfix-policyd-spf-perl package depends on the mail::spf and the netaddr::ip perl modules. therefore we are going to install them now using the perl shell. start the perl shell like this:

perl -mcpan -e shell

if you run the perl shell for the first time, you will be asked a few questions. you can accept all default values. you will also be asked about the cpan repositories to use. select repositories that are close to you.

after the initial perl shell configuration, we can start to install the needed modules. to install mail::spf, simply run

install mail::spf

in my case, it tried to install module::build (which is a dependency), but then it failed. if this happens to you, simply quit the perl shell by typing


then start the perl shell again:

perl -mcpan -e shell

and try to install mail::spf again:

install mail::spf

this time it should succeed, and you should see that it also installs the modules net:ns::resolver::programmable and netaddr::ip on which mail::spf depends.

a successful installation of mail:spf should end like this:

installing /usr/local/bin/spfquery
writing /usr/local/lib/perl/5.8.8/auto/mail/spf/.packlist
/usr/bin/make install -- ok

because netaddr::ip has already been installed, we can now leave the perl shell:


3 install postfix-policyd-spf-perl
next we download postfix-policyd-spf-perl from spf: software to the /usr/src/ directory and install it to the /usr/lib/postfix/ directory like this:

cd /usr/src
wget http://www.openspf.org/blobs/postfix...l-2.001.tar.gz
tar xvfz postfix-policyd-spf-perl-2.001.tar.gz
cd postfix-policyd-spf-perl-2.001
cp postfix-policyd-spf-perl /usr/lib/postfix/policyd-spf-perl

then we edit /etc/postfix/master.cf and add the following stanza at the end:

vi /etc/postfix/master.cf

policy unix - n n - - spawn
user=nobody argv=/usr/bin/perl /usr/lib/postfix/policyd-spf-perl
(the leading spaces before user=nobody are important so that postfix knows that this line belongs to the previous one!)

then open /etc/postfix/main.cf and search for the smtpd_recipient_restrictions directive. you should have reject_unauth_destination in that directive, and right after reject_unauth_destination you add check_policy_service unixrivate/policy like this:

vi /etc/postfix/main.cf

smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject _unauth_destination,check_policy_service unixrivate/policy
or like this:

smtpd_recipient_restrictions =
check_policy_service unixrivate/policy
it is important that you specify check_policy_service after reject_unauth_destination or else your system can become an open relay!

then restart postfix:

/etc/init.d/postfix restart

that's it already. you should check the readme file that comes with the postfix-policyd-spf-perl package, it contains some important details about how postfix-policyd-spf-perl processes emails, e.g. like this part from the postfix-policyd-spf-perl-2.0001 readme:

this version of the policy server always checks helo before mail from (older
versions just checked helo if mail from was null). it will reject mail that
fails either mail from or helo spf checks. it will defer mail if there is a
temporary spf error and the message would othersise be permitted
(defer_if_permit). if the helo check produces a reject/defer result, mail from
will not be checked.

if the message is not rejected or deferred, the policy server will prepend the
appropriate spf received header. in the case of multi-recipient mail, multiple
headers will get appended. if mail from is anything other than completely empty
(i.e. ) then the mail from result will be used for spf received (e.g. mail
from none even if helo is pass).

the policy server skips spf checks for connections from the localhost (127.) and
instead prepends and logs 'spf skipped - localhost is always allowed.'

4) ip rotation via ip tables

first we need creating interface aliases for your public ips.

let's say you have 5 ips

#ifup eth0:1
#ifup eth0:2
#ifup eth0:3
#ifup eth0:4

now the iptables part.make sure your iptables support for statistic match module.

# iptables -m statistic -h
statistic match options:
--mode mode match mode (random, nth)
random mode:
--probability p probability
nth mode:
--every n match every nth packet
--packet p initial counter value (0 <= p <= n-1, default 0)
next continue with iptables rule for rotating source ip addresses.

# iptables -t nat -i postrouting -m state --state new -p tcp --dport 25 -o eth0 -m statistic --mode nth --every 5 -j snat --to-source 202.xxx.xx.2
# iptables -t nat -i postrouting -m state --state new -p tcp --dport 25 -o eth0 -m statistic --mode nth --every 5 -j snat --to-source 202.xxx.xx.3
# iptables -t nat -i postrouting -m state --state new -p tcp --dport 25 -o eth0 -m statistic --mode nth --every 5 -j snat --to-source 202.xxx.xx.4
# iptables -t nat -i postrouting -m state --state new -p tcp --dport 25 -o eth0 -m statistic --mode nth --every 5 -j snat --to-source 202.xxx.xx.5
# iptables -t nat -i postrouting -m state --state new -p tcp --dport 25 -o eth0 -m statistic --mode nth --every 5 -j snat --to-source 202.xxx.xx.6

6) reverse dns

the easiest way to get rdns is to buy a domain with your vps and ask you hosted to set up rdns with your vps, they will do it for free, a domain is not really expensive and it will save you some time .

7) whitelisting

whitelisting can help you to get your emails reach inbox instead of spam folder,

i will teach you now how to whitelist your self on some spam filter systems and some email providers.

first of all you must have a domain which have valid rdns with your server, and you must have a web site on your domain. this may takes you some time, but i highly recommend you to make a fake marketing agency web site, i know this may sounds unethical and, maybe even, illegal ( okay, it's hard to believe it could illegal since there is tons of hosting companies, web design agency and so on, which are not registered anywhere ), and you can make some simple looking web site explaining that you are providing email marketing services to your clients. make sure you make it clear that you have a zero tolerance to spam and that all emails you have in your lists are generated by you, bla bla, opt in, bla bla, cpan spam, bla bla, just google some email marketing agency and see what they say . this will helps you a lot to get whitelisted almost anywere.

- aol whitelistening

url : http://postmaster.aol.com/cgi-bin/wh...list_guides.pl

it's very easy to get on their whitelist, but if they get tons of spam complains about your message, you will be removed to blacklist list very fast ^^

- yahoo whitelistening

url : http://help.yahoo.com/l/us/yahoo/mai...er/bulkv2.html

it's hard to get whitelisted on yahoo, but give it a try.

hotmail whitelistening

url : https://support.msn.com/eform.aspx?p...rpp&ct=eformts

spam filters where you can ask for whitelistening

- v4bl

the spamhaus whitelist - only with invite, so it's almost impossible to get there, but it's worth if you can

basically here is the list of, almost, all spam filter systems, so google their unblacklistening or whitelistening pages :

efnet rbl