Configure a new domain in OpenDKIM
#!/bin/bash
DOMAIN="$1"
SELECTOR="mail"
if [ -z "${DOMAIN}" ]; then
echo "Usage: $0 domain.name"
exit
fi
if [ -z "$( dig +short ${DOMAIN} mx)" ]; then
echo "Domain has no MX records"
exit
fi
mkdir /etc/opendkim/keys/${DOMAIN}
echo "${SELECTOR}._domainkey.${DOMAIN} ${DOMAIN}:mail:/etc/opendkim/keys/${DOMAIN}/${SELECTOR}.private" >>/etc/opendkim/KeyTable
echo "*@${DOMAIN} ${SELECTOR}._domainkey.${DOMAIN}" >>/etc/opendkim/SigningTable
echo "${DOMAIN}" >>/etc/opendkim/TrustedHosts
sudo opendkim-genkey -b 1024 -d "${DOMAIN}" -D /etc/opendkim/keys/${DOMAIN} -s ${SELECTOR} -v
sudo chown opendkim:opendkim /etc/opendkim/keys/${DOMAIN}/${SELECTOR}.private
sudo cat /etc/opendkim/keys/${DOMAIN}/${SELECTOR}.txt