snipe / snipe-it

A free open source IT asset/license management system
https://snipeitapp.com
GNU Affero General Public License v3.0
11.17k stars 3.2k forks source link

SMTP not working - Mail could not be sent - no app logs #13872

Closed YoBii closed 1 month ago

YoBii commented 1 year ago

Debug mode

Describe the bug

Test mail returns Mail could not be sent. No additional error message provided. Check your mail settings and your app log.

However application log (storage/logs/laravel.log) (or log tab in debug panel) doesn't show anything.

Reproduction steps

  1. Set mail options in env file
  2. (perform php artisan cache:clear and php artisan config:clear)
  3. Use test mail button

Expected behavior

I expect test mail and sending mail in general to work.

Screenshots

image

Snipe-IT Version

v6.2.3 build 11936 (gb47e734b3)

Operating System

Debian 11 (bullseye)

Web Server

apache2

PHP Version

7.4.33

Operating System

Windows

Browser

Firefox

Version

119

Device

No response

Operating System

No response

Browser

No response

Version

No response

Error messages

[2023-11-10 13:45:59] production.ERROR: Your APP_URL in your .env is misconfigured - it is: inventory.sub.domain.com. Many things will work strangely unless you fix it.
[2023-11-10 13:45:59] production.ERROR: Your APP_URL in your .env is misconfigured - it is: inventory.sub.domain.com. Many things will work strangely unless you fix it.
[2023-11-10 13:45:59] production.ERROR: Your APP_URL in your .env is misconfigured - it is: inventory.sub.domain.com. Many things will work strangely unless you fix it.
[2023-11-10 13:45:59] production.ERROR: Your APP_URL in your .env is misconfigured - it is: inventory.sub.domain.com. Many things will work strangely unless you fix it.
[2023-11-10 13:46:00] production.ERROR: Your APP_URL in your .env is misconfigured - it is: inventory.sub.domain.com. Many things will work strangely unless you fix it.
[2023-11-10 13:46:32] production.ERROR: Your APP_URL in your .env is misconfigured - it is: inventory.sub.domain.com. Many things will work strangely unless you fix it.
[2023-11-10 13:46:34] production.ERROR: Your APP_URL in your .env is misconfigured - it is: inventory.sub.domain.com. Many things will work strangely unless you fix it.
[2023-11-10 13:56:18] production.ERROR: Your APP_URL in your .env is misconfigured - it is: inventory.sub.domain.com. Many things will work strangely unless you fix it.
[2023-11-13 10:14:39] production.ERROR: Error: Class 'Laravel\Socialite\SocialiteServiceProvider' not found in /var/www/html/snipe-it/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepos
itory.php:208
Stack trace:
#0 /var/www/html/snipe-it/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php(144): Illuminate\Foundation\ProviderRepository->createProvider()
#1 /var/www/html/snipe-it/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php(61): Illuminate\Foundation\ProviderRepository->compileManifest()
#2 /var/www/html/snipe-it/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(659): Illuminate\Foundation\ProviderRepository->load()
#3 /var/www/html/snipe-it/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/RegisterProviders.php(17): Illuminate\Foundation\Application->registerConfiguredProviders()
#4 /var/www/html/snipe-it/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(237): Illuminate\Foundation\Bootstrap\RegisterProviders->bootstrap()
#5 /var/www/html/snipe-it/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(310): Illuminate\Foundation\Application->bootstrapWith()
#6 /var/www/html/snipe-it/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(127): Illuminate\Foundation\Console\Kernel->bootstrap()
#7 /var/www/html/snipe-it/artisan(35): Illuminate\Foundation\Console\Kernel->handle()
#8 {main}

Additional context

Laravel: 8.83.27 DB: mysql SELinux: disabled Context: Application has been used in production for some time. Mail was always set to log as I didn't need it. Things have changed - now I want mail to work.

Unfortunately I can't get a working setup of SMTP in snipe-it. Test mail returns Mail could not be sent. No additional error message provided. Check your mail settings and your app log.

However nothing is printed to the application log (storage/logs/laravel.log) (or log tab in debug panel). I provided error messages from the log but I think those were unrelated and I was able to fix both of them. More details on this below. Point is, these were the only two types of errors in the log. Nothing else. Nothing about mail specifically.

.env These are my mail settings. I am trying to use an SMTP relay account on Office 365. This works for all other applications I am hosting. I double checked the credentials.

MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=serviceaccount@service.mydomain.com
MAIL_PASSWORD=redacted
MAIL_ENCRYPTION=null
MAIL_FROM_ADDR=snipeit@mydomain.com
MAIL_FROM_NAME='Snipe-IT'
MAIL_REPLYTO_ADDR=me@mydomain.com
MAIL_REPLYTO_NAME='Snipe-IT'
MAIL_AUTO_EMBED_METHOD='attachment'

I also tried setting encryption to tls (btw it would be great if environment options like these were documented. I could only find null in https://snipe-it.readme.io/docs/configuration)

Networking As I am behind a firewall I tried to connect to the mail server on the specified port using telnet from the host running snipe-it. It works just fine so it's not a networking issue (I am running other applications that are using SMTP in the same network as well..)

Upgrade Today I updated SnipeIT and could do so successfully after solving some permission problems with composer. It wasn't able to write to /var/www/.cache and apparently that was related to the socialite error in the log. After solving this upgrade.php printed that all permissions check out. I carefully checked the output of the script for any errors during upgrade. Seems fine. However the problem with mail persists.

Previously Before all of this when I tried setting up mail the first time I noticed my lavarel.log was flooded with

[2023-11-10 13:36:17] production.ERROR: Your APP_URL in your .env is misconfigured - it is: inventory.sub.domain.com. Many things will work strangely unless you fix it.

I solved this by prepending the APP URL with https://. Error never reoccurred since then but that didn't change anything about mail not working. Just thought I mention this.

Summary Test mail is returning 500 internal server error and nothing is printed to lavarel.log.

Please let me know when there's anything missing I can provide.

Thanks for reading and all your work.

welcome[bot] commented 1 year ago

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

snipe commented 1 year ago

Are you running SELinux? https://snipe-it.readme.io/docs/linuxosx#notes-on-selinux

Snipe-IT Documentation
Linux/OSX
Setting up a web server can sound daunting for folks who don't normally do that kind of thing. This guide will help you walk through the configuration for Apache or Nginx on Linux and OSX.Using ApacheThe most common setup for Snipe-IT on a linux server is to use Apache, so if you're not sure what to...
YoBii commented 12 months ago

As stated above I am not running SELinux. Debian doesn't come with it and it wasn't installed manually either. I double checked this now.

snipe commented 11 months ago

Can you provide a full stack trace of the mail error? The one above only includes the socialite issue.

YoBii commented 11 months ago

Sorry but I can't. Nothing is written to laravel.log when Send Test fails.

A while back I assumed this was a permission problem but I think I ruled that out. When I purposefully put a wrong APP_URL that will produce errors in laravel.log. So logging seems to work in general.

EDIT: The last entry in laravel.log is from 2023-11-13. I have APP_DEBUG=true in my .env file.

esmsesms commented 10 months ago

We observed similar issue at Version v6.2.2 - build 11714 (master) on top of Ubuntu 22.04.3 LTS (Jammy Jellyfish) with all patches applied as of 2023-01-22. SMTP is set to smtp.gmail.com (Google Workspace Enterprise) with the email account fully tested.

yashas-tantri commented 9 months ago

Having the same issue where using the IIS server.

YoBii commented 7 months ago

Can we provide any more info to help solve this issue?

bibz0r commented 6 months ago

Experiencing the same issue with Docker running on Ubuntu 22.04.4. (Office 365).

/edit: Strangely when using port 25 it works! (took me a few hours until I've came to the conclusion)

In my case I'm using office 365 with a setup relay.

YoBii commented 6 months ago

@bibz0r hmm, I tried port 25 without success. Would you mind sharing you .env / mail configuration or check if mine is different from yours (you can see mine in the initial post)?

phw-lopa commented 5 months ago

I have the similar error. Using the latest Docker-Image. In the docker-env I have my settings. They are not working, even If I use MAIL_* from here or MAIL_ENV_* from here

Weird is that in the error-message it seems like none of my ENV-Vars is used as there is one dummy-entry (your_email_username):

[2024-05-30 15:28:57] production.ERROR: Failed to authenticate on SMTP server with username "your_email_username" using 2 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "535", with message "535 5.7.8 Authentication credentials invalid.
". Authenticator PLAIN returned Expected response code 235 but got code "535", with message "535 5.7.8 Authentication credentials invalid.
". {"userId":3,"exception":"[object] (Swift_TransportException(code: 0): Failed to authenticate on SMTP server with username \"your_email_username\" using 2 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code \"535\", with message \"535 5.7.8 Authentication credentials invalid.
\". Authenticator PLAIN returned Expected response code 235 but got code \"535\", with message \"535 5.7.8 Authentication credentials invalid.
\". at /var/www/html/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/AuthHandler.php:191)
Winniepoom commented 4 months ago

Had same issue here with Docker install no logs in container or error. image

YoBii commented 1 month ago

For everyone still struggling with this:

When you're using Office 365 you can't just put any sender as MAIL_FROM_ADDR like you may be used to.
The simplest option is to have from address and username identical i.e. MAIL_FROM_NAME = MAIL_USERNAME.

Alternatively if you want to use another address..

However Microsoft will be turning off smtp client submission using app passwords entirely in 2025. We'll need a way to use modern authentication from Snipe-IT's side or migrate to using a connector and whitelist the IP of our Snipe-IT Instance.

Closing as the issue is resolved for me.