BookStack icon indicating copy to clipboard operation
BookStack copied to clipboard

Issues setting up M365 SMTP email sending

Open Milgerdas opened this issue 1 year ago • 3 comments

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

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"
[email protected]

MAIL_HOST=smtp.office365.com
MAIL_PORT=587
[email protected]
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', '[email protected]'),
        '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.

Milgerdas avatar May 22 '24 11:05 Milgerdas

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 avatar May 22 '24 13:05 ssddanbrown

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 avatar May 23 '24 06:05 Milgerdas

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 avatar Oct 14 '24 12:10 NinjaAway