Issues setting up M365 SMTP email sending #4789

Closed
opened 2026-02-05 09:15:49 +03:00 by OVERLORD · 4 comments
Owner

Originally created by @Milgerdas on GitHub (May 22, 2024).

Attempted Debugging

  • I have read the debugging page

Searched GitHub Issues

  • I have searched GitHub for the issue.

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.

Originally created by @Milgerdas on GitHub (May 22, 2024). ### Attempted Debugging - [X] I have read the debugging page ### Searched GitHub Issues - [X] I have searched GitHub for the issue. ### 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](https://github.com/BookStackApp/BookStack/assets/17928399/94cdc74d-65c8-44fd-9471-1d5fa573ec8e) 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.
OVERLORD added the 🐕 Support label 2026-02-05 09:15:49 +03:00
Author
Owner

@ssddanbrown commented on GitHub (May 22, 2024):

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?

@ssddanbrown commented on GitHub (May 22, 2024): 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`?
Author
Owner

@Milgerdas commented on GitHub (May 23, 2024):

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.

@Milgerdas commented on GitHub (May 23, 2024): 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.
Author
Owner

@NinjaAway commented on GitHub (Oct 14, 2024):

Hello,
Got the same issue.
Host : Ubuntu 20.04 LTS
Bookstack version : 24.05.3
Log : None
Specific variable : Port 25 without any auth

SMTP host can be join from the docker API.

  • ping smtp.host.com --> OK
  • nslookup smtp.host.com --> OK

Works well with other equipments (servers and printers).

@NinjaAway commented on GitHub (Oct 14, 2024): Hello, Got the same issue. Host : Ubuntu 20.04 LTS Bookstack version : 24.05.3 Log : None Specific variable : Port 25 without any auth SMTP host can be join from the docker API. - ping smtp.host.com --> OK - nslookup smtp.host.com --> OK Works well with other equipments (servers and printers).
Author
Owner

@ssddanbrown commented on GitHub (Aug 29, 2025):

Since this is relatively old I'm going to close off this issue.
If the issue remains, feel free to open a new support request, with details of the error observed using the test send functionality in the maintenance area of BookStack.

@ssddanbrown commented on GitHub (Aug 29, 2025): Since this is relatively old I'm going to close off this issue. If the issue remains, feel free to open a new support request, with details of the error observed using the test send functionality in the maintenance area of BookStack.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#4789