Search code examples
phpoffice365swiftmailer

Authenticating with office365 relay connector via digital certificate in swift mailer


I'm transferring from a IP based office365 exchange connector to a digital certificate one as I'm moving to a elastic beanstalk web cluster which won't have a single ip for me to authenticate on

I've tried reading the limited documentation available here https://learn.microsoft.com/en-us/previous-versions/exchange-server/exchange-150/dn910993(v=exchg.150) which helped me figure out I need to send a TLS certificate with a specific domain, but I don't know how to actually send that certificate in PHP with SwiftMailer

The closest example I've found is this example

$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->SMTPAuth = false;
$mail->SMTPOptions = [
    'ssl' => [
        'verify_peer'  => true,
        'local_cert' => '/path/to/client_cert_and_key.pem'
    ]
];

where local_cert would be my digital certificate, but I'm not sure how I would generate a certificate with the correct domain, can I just re-use my HTTPS cert?


Solution

  • I generated a certificate using letsencrypt, got the pem files out of /etc/letsencrypt/ then passed in fullchain.pem as local_cert and privkey.pem as local_k when initialising the smtp transport, then I added a digital certificate connector for *.domain and I was able to authenticate