BookStackApp / BookStack

A platform to create documentation/wiki content built with PHP & Laravel
https://www.bookstackapp.com/
MIT License
14.28k stars 1.8k forks source link

Issues setting up M365 SMTP email sending #5026

Open Milgerdas opened 1 month ago

Milgerdas commented 1 month ago

Attempted Debugging

Searched GitHub Issues

Describe the Scenario

Hello,

I have added SMTP creds to a new Bookstack setup, getting an error on the Test email function via Maintenance

image

Details:

Ubuntu 22.04 php 8.1.2 composer 2.2.6

.env file

APP_KEY=base64:****
APP_URL=http://kb.domain.com
DB_HOST=localhost
DB_DATABASE=bookstack
DB_USERNAME=bookstack
DB_PASSWORD=****

MAIL_DRIVER=smtp
MAIL_FROM_NAME="Knowledge Base"
MAIL_FROM=bookstack@domain.com

MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=bookstack@domain.com
MAIL_PASSWORD=****
MAIL_ENCRYPTION=tls

Also tried with mail verify ssl false, both tls and starttls, to regenerate app key (MFA disabled on the inbox used).

/app/Config/mail.php file

<?php

// Configured mail encryption method.
// STARTTLS should still be attempted, but tls/ssl forces TLS usage.
$mailEncryption = env('MAIL_ENCRYPTION', null);

return [

    // Mail driver to use.
    // From Laravel 7+ this is MAIL_MAILER in laravel.
    // Kept as MAIL_DRIVER in BookStack to prevent breaking change.
    // Options: smtp, sendmail, log, array
    'default' => env('MAIL_DRIVER', 'smtp'),

    // Global "From" address & name
    'from' => [
        'address' => env('MAIL_FROM', 'bookstack@example.com'),
        'name'    => env('MAIL_FROM_NAME', 'Bookstack'),
    ],

    // Mailer Configurations
    // Available mailing methods and their settings.
    'mailers' => [
        'smtp' => [
            'transport' => 'smtp',
            'scheme' => null,
            'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
            'port' => env('MAIL_PORT', 587),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'verify_peer' => env('MAIL_VERIFY_SSL', true),
            'timeout' => null,
            'local_domain' => env('MAIL_EHLO_DOMAIN'),
            'tls_required' => ($mailEncryption === 'tls' || $mailEncryption === 'ssl'),
        ],

        'sendmail' => [
            'transport' => 'sendmail',
            'path' => env('MAIL_SENDMAIL_COMMAND', '/usr/sbin/sendmail -bs'),
        ],

        'log' => [
            'transport' => 'log',
            'channel' => env('MAIL_LOG_CHANNEL'),
        ],

        'array' => [
            'transport' => 'array',
        ],

        'failover' => [
            'transport' => 'failover',
            'mailers' => [
                'smtp',
                'log',
            ],
        ],
    ],

    // Email markdown configuration
    'markdown' => [
        'theme' => 'default',
        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],
];

While t/s I did try php artisan cache:clear and config:clear with the same result.

Sendmail in this case not really an option for the grand scheme how bookstack will be used in our company env, so havent/wont try it.

Any help would be highly appreciated, thank you!

Exact BookStack Version

v24.05

Log Content

No response

Hosting Environment

Ubuntu 22.04, installed with an official installation script for the correct Linux version.

ssddanbrown commented 1 month ago

Hi @Milgerdas, Have you confirmed if the host machine has general connection visibility of that address, so are you able to ping smtp.office365.com?

Milgerdas commented 1 month ago

Hey @ssddanbrown, Yes, sorry for not mentioning, the machine where bookstack is running has general connectivity and can ping smtp.office365.com, reach other VMs. Maybe worth noting bookstack machine is in the same subnet as other VMs that are able to send mails via M365 Exchange, our domain is not in any blacklists.