Enable DKIM and have Exim SMTP banner use the accounts dedicated IP in DirectAdmin for PHP mail

Change the SMTP banners to use a specific domain according to IP and enable DKIM

Updated exim to use the latest version and latest version exim.conf

cd /usr/local/directadmin/custombuild
vi options.conf

Now, set custombuild to update exim:

exim=yes
eximconf=yes

Update custombuild to use new settings and install latest version of exim

./build update
./build exim
./build exim_conf

For PHP mail, you need to add the following lines to the top of your /etc/exim.conf :

Ref: https://help.directadmin.com/item.php?id=257

untrusted_set_sender = *
no_local_from_check

So now that's done. Edit directadmin conf to send mail from the user account's dedicated IP.

vi /usr/local/directadmin/conf/directadmin.conf

Add the following

add_domain_to_domainips=1
dkim=1

Restart DirectAdmin

SPF is added automatically by DirectAdmin, do not use the DEPRECATED dns_spf=1

service directadmin restart

DO NOT USE the updated DirectAdmin DKIM guide if you're using Exim 4.3 or greater: http://help.directadmin.com/item.php?id=569

Finally, run the directadmin task.queue

Do this for the first time:

echo "action=rewrite&value=domainips" >> /usr/local/directadmin/data/task.queue
echo "action=rewrite&value=helo_data" >> /usr/local/directadmin/data/task.queue
echo "action=rewrite&value=dkim" >> /usr/local/directadmin/data/task.queue

Do this if domain IPs become out of sync

echo "action=rewrite&value=domainips&empty=yes" >> /usr/local/directadmin/data/task.queue
echo "action=rewrite&value=helo_data&empty=yes" >> /usr/local/directadmin/data/task.queue

Do this for a single domain

echo "action=rewrite&value=domainips&domain=DOMAIN.COM" >> /usr/local/directadmin/data/task.queue  ### Removes previous values, and starts from scratch
echo "action=rewrite&value=helo_data&ip=1.2.3.4" >> /usr/local/directadmin/data/task.queue
/usr/local/directadmin/scripts/dkim_create.sh DOMAIN.COM

That should do it...

Change the PHP mail SMTP Sender banner

To Change the "Sender" info we have to do the following:

cd /usr/local/directadmin/data/templates/custom/
cp /usr/local/directadmin/data/templates/virtual_host2.conf /usr/local/directadmin/data/templates/custom/
cp /usr/local/directadmin/data/templates/virtual_host2_secure.conf /usr/local/directadmin/data/templates/custom/
sed -i 's/`USER`@`DOMAIN`/no-reply@`DOMAIN`/g' ./virtual_host2*.conf
echo "action=rewrite&value=httpd" >> /usr/local/directadmin/data/task.queue
/usr/local/directadmin/dataskq d

Now we add required lines to /etc/exim.conf at the very top of file:

local_from_check = false
untrusted_set_sender = *

Restart exim.

service exim restart

OLD WAY

Credit: http://forum.directadmin.com/showthread.php?t=36468&page=5

cd /etc/virtual
vi domainips

Paste the following into /etc/virtual/domainips YOUR_DOMAIN:YOUR_DOMAIN_IP_ADDRESS

vi /etc/virtual/domainips
domaina.com:111.111.111.111
domainb.com:222.222.222.222
domainc.com:333.333.333.333

Now we do the reverse IP lookup. YOUR_DOMAIN_IP_ADDRESS:YOUR_SUB_DOMAIN.YOUR_DOMAIN

vi /etc/virtual/smtp_active_hostnames

Paste this into /etc/virtual/smtp_active_hostnames

111.111.111.111:mail.domain1.com
222.222.222.222:mail.domain2.com
333.333.333.333:mail.domain3.com

Next create /etc/virtual/helo_data

vi /etc/virtual/helo_data

Paste the following:

aaa.aaa.aaa.aaa: mail.domain1.com
bbb.bbb.bbb.bbb: mail.domain2.com
ccc.ccc.ccc.ccc: mail.domain3.com

Now edit your /etc/exim.conf again, and make sure the top of the file looks like the following

# proper SMTP sender START #                                                                                                                                                                
local_interfaces = 127.0.0.1 : 111.111.111.111 : 222.222.222.222 : 333.333.333.333
smtp_active_hostname = ${lookup{$received_ip_address}iplsearch{/etc/virtual/smtp_active_hostnames}{$value}}
smtp_banner = "$smtp_active_hostname ESMTP $tod_full"  
no_local_from_check
untrusted_set_sender = * 
# proper SMTP sender END #

Now we REPLACE the remote_smtp part in /etc/exim.conf with:

remote_smtp:
driver = smtp
interface = "${lookup{$sender_address_domain}lsearch{/etc/virtual/domainips}{$value}{aaa.aaa.aaa.aaa}}"
helo_data = "${lookup{$sending_ip_address}lsearch{/etc/virtual/helo_data}{$value}{$primary_hostname}}" 

Restart exim

service exim restart
Tags: Linux exim DirectAdmin DKIM spam SMTP PHP mail email