How to use msmtp with DKIM to send as other organisation

476 Views Asked by At

I have a off the shelf PHP app it uses msmtp to do its mail sending. My some of my users are part of another external_organisation, and they need to send email from my php app as their external_organisation.com email address. And some need to send as mycompany.com

For the most part this has been working all ok, until now...

external_organisation has recently setup DKIM, and have told me I need to give them a key and sign emails being sent as them or they will stop working soon. I have searched ALL of the internet three times, but I cant work out how to make this happen.

Can I please get some pointers?

I assume I need to configure msmtp, and not PHPMailer ? I really am not sure about this.

1

There are 1 best solutions below

2
On

This question would be better suited to ServerFault as it's a server config question, not a programming question.

It's definitely better and faster to configure your mail server to do the signing rather than PHPMailer, but you need some way of specifying the selector to sign with (assuming you want to use more than one). Most mail servers that support DKIM allow you to do this via a specially-named header, but you'll need to refer to their docs on it.

The simplest way to configure things is to sign with your own private key and get the external org to put your public key in their DNS in a TXT record under your selector, for example in yourservice._domainkey.external-org.example.com

Alternatively, they can set up a CNAME for your service in their DNS, and you then have control over the public key in your DNS. Something like external-org.yourservice.example.com.

Either way, wherever the signing happens needs access to the private key, and the domain and selector need to point at a public key in DNS.

Minor tip: saying things like "I have searched ALL of the internet three times" is unlikely to make a good impression. There are a zillion articles on how to use DKIM and they will all say basically the same thing, because it is the same thing.