Skip to content

Instantly share code, notes, and snippets.

@daubac402
Last active February 24, 2022 01:59
Show Gist options
  • Save daubac402/3354b53f0a27ff452a8c0f51b983eb04 to your computer and use it in GitHub Desktop.
Save daubac402/3354b53f0a27ff452a8c0f51b983eb04 to your computer and use it in GitHub Desktop.
Setup DKIM on Postfix Mail server.txt
$ MYDOMAIN=yourdomain.com
$ mkdir -p /etc/mail/dkim-keys/$MYDOMAIN
$ cd /etc/mail/dkim-keys/$MYDOMAIN
$ opendkim-genkey -t -s mail -d $MYDOMAIN
# if opendkim-genkey command is not found, install it#
# Eg: With Centos 7:
$ rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
$ sudo yum install -y opendkim
# 2 news file will be generated: mail.private and mail.txt
# add this line to /etc/mail/dkim-key
$ vim /etc/mail/dkim-key
->
*@you:you:/etc/mail/dkim-keys/yourdomain.com/mail.private
# for eg:
*@ec2-user:ec2-user:/etc/mail/dkim-keys/yourdomain.com/mail.private
# Edit DKIM configuration file /etc/opendkim.conf and update below values in configuration file.
$ vim /etc/opendkim.conf
->
Domain yourdomain.com
KeyFile /etc/mail/dkim-key
Selector mail
Socket inet:8892@localhost
# Now edit POSTFIX configuration file /etc/postfix/main.cf and add following values at the end of file
$ vim /etc/postfix/main.cf
->
milter_default_action = accept
milter_protocol = 2
smtpd_milters = inet:localhost:8892
non_smtpd_milters = inet:localhost:8892
# Configure DNS Entry using info from mail.txt
...
# Set permission
$ sudo chown opendkim:opendkim /etc/mail/dkim-key
$ sudo chmod 400 /etc/mail/dkim-key
# Restart Service
$ sudo service opendkim restart
$ sudo service postfix restart
# Verify DKIM
$ mail -vs "Test DKIM" test_email@gmail.com < /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment