I've read the tutorial posted by MountainX (Setup DKIM (DomainKeys) for Ubuntu, Postfix and Mailman), but I can't figure out how to apply these steps if I want to host and send e-mails for several domains. Does anybody have a clue?
I've read the tutorial posted by MountainX (Setup DKIM (DomainKeys) for Ubuntu, Postfix and Mailman), but I can't figure out how to apply these steps if I want to host and send e-mails for several domains. Does anybody have a clue?
Good! I figured this out from the post mentioned in the question. I made a kind of mix between the answer itself and the links provided in it. Specially the fourth link is the one I used.
So the thing goes like this. Suppose you've got a server or VPS and make one of your domains to be the main domain and be used as the server name (in my example: mydomain.com).
So, first of all, we'll change to root to make things easier, but you can skip this step and use
sudo
before every command.Now, we install OpenDKIM:
Let's fix the configuration file. We're opening
/etc/opendkim.conf
for editing. I use nano, but it's the same with other editor.Once opened, make it look like this. If you feel comfortable, you can change some options, but the
Domain
,KeyFile
andSelector
must remain commented.Next, we create some of the folder and files that will hold information about what should OpenDKIM use and process. For now, the
TrustedHosts
file. We create and edit it:We must put into this file a list of trusted addresses: localhost and 127.0.0.1, and your server name and IP:
Now we edit OpenDKIM config file.
And add these lines at the end of the file. They'll tell OpenDKIM in which port it should expect signing requests:
We open the Postfix config file.
And add these lines to the end of the file. They'll tell Postfix that it should send e-mails to be signed and where.
If you're not adding domains right now, you can restart everything, so the configuration takes effect.
Done! The server is ready to work with DKIM. Now, you need to add your domains to this system. The following process is the same for all the domains you want to add. I'll use otherdomain.com for the example, replace it with your own.
Remember I was root from before, but if you're not, run
sudo su
or precede your commands with the keywordsudo
.First, we create a directory for our domain and go inside of it:
Now we generate a key for the domain:
We give the OpenDKIM user ownership of the newly created file:
And we open the
KeyTable
file to add our new key for our new domain:We add it to the end of the file (after all other domains we may have here):
We open the
SigningTable
file.And append at the end of the file (again, we'll have one line for each domain):
This SigningTable lists all mails which get signed. Just by adding a domain name, all mails from that domain will be signed.
I'm not sure of the necessity to do the next step, but I just did it, just in case... We open the
TrustedHosts
file.And add at the end of the file:
One last thing: we show the contents of the file
/etc/opendkim/keys/otherdomain.com/default.txt
.And add the information between the quotes to a
TXT
record in the DNS Zone of the domain, and we must also usedefault._domainkey
as the name of the record. NOTE: "between the quotes" is the text that starts with "v=DKIM1;k=rsa; p=WIGfM...
".If we're done adding domains (by now), we restart everything to apply the changes.
Done!
This script automates the part after "Done! The server is ready to work with DKIM"
To help automate this process a little I created this bash script. Just add one 'domain.com' per line inside the domains=() array.
First create the files and directories if they do not already exist
spfs.txt file will contain all the spf records you need to add to your DNS records for each domain.
NOTE: do not run more than once, it does not check to see if a domain already exists. Script also needs to be run as root.
This script automates the part after "Done! The server is ready to work with DKIM"
To help automate this process a little I created this bash script. Just add one domain like 'example.com' per line inside the domains=() array.
This script creates the files for you and checks if a line is already in the file
Spfs.txt is removed and recreated everytime its run and checks the 2nd line of default.txt against spfs.txt before appending
You must place your servers ipv4 and ipv6 (if you have them) in the variables provided. It checks if they arent empty
you can run this file multiple times thanks to the checks added.