Hello,
I don’t regularly send emails directly from IN, since I prefer to download documents and email them myself to my clients. That being said, some core functions of IN rely on being able to send emails, like bulk document downloading. This is how I noticed that emails don’t work anymore on my install - I am runnig on a newer server since the last time it worked, so it may be related.
Here is the way my .env is setup, as previously working:
MAIL_MAILER=smtp
MAIL_HOST=smtp-relay.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
[email protected]
MAIL_FROM_NAME="name"
I am using Google Workspace SMTP relay with an app password created for Invoice Ninja. I updated my Google Workspace settings to allow my new server IP and I edited my DNS DMARC settings accordingly on my registrar config.
Well, the above doesn’t work anymore, so I wondered if that might be due to some update that changed the syntax in the .env file or something (like the self-host troubleshooting page says I should have a SERVER_NAME=
value in .env, but I’m not share what it should be - and apparently that was not necessary for my config either, since I never used that value before. Still, I will happily add that variable if it helps, I would just need to know what to input there.
Here is the link to that page, if anyone is interested:
So, I tried running a clean install in another test subdomain I created to see what result I would get with the “Send Test email”, since there is no such test button in the main app once installed (unfortunately).
Well, it didn’t work, no matter what port I tried using. I even tried turning off two-factor authentification and turning on “less secure apps” for my Google account and using my main email password, but I still got this:
Connection could not be established with host "smtp-relay.gmail.com:587": stream_socket_client(): Unable to connect to smtp-relay.gmail.com:587 (Network is unreachable)
Apparently, this is a common issue when using Laravel to connect to Gmail (if anyone has any idea on how to fix that, I’d very happy), and the “solution” (more like a workaround) I have read the most is to switch the mail driver to Sendmail. The thing is, by doing that, my server now apparently completely bypasses Google, since I can use funky values under USERNAME and HOST and such. The following settings correctly sent me an email (I had “domain.com” switched to my real domain, though) :
Surely, sending emails directly from my server is not great for deliverability (I used to do that and I switched to Google exactly because I often ended up in junk mail despite having proper DNS records and a dedicated IP - the IP reputation is a strong value apparently for agressive spam filters). Still, I decided to rock it for a while to test it out so I went ahead and changed my .env file in my production app to “Sendmail”. According to some Youtube Video ( How to fix Connection could not be established with host smtp.gmail.com✔️ - YouTube) I also had to change SMTP
to Sendmail
in ./config/mail.php" line 16, so I did that:
'default' => env('MAIL_MAILER', 'sendmail'),
Now, after the obligatory php artisan optimize
on my production app, I went to my test company and tried sending myself an invoice. Nothing happened. I tried downloading a zip of several documents, where IN is supposed to email me when the zipping is done: nothing happened.
To make sure my install, besides IN functions, can send emails with the current settings, I tried the following:
php artisan tinker
\Mail::raw('hello world', function($message) {
$message->subject('Testing email')->to('[email protected]');
});
And it sent me an email, yay! So something is working somewhere.
Back to the console, I tried forcing php artisan queue:work
and then… boom, it did a milllion things, including sending me several test emails that were stuck in the queue! Clearly, I have a queue issue on top of the SMTP issue. I’m running the Laravel Supervisor service on my server and I have those variables setup in my .env:
QUEUE_CONNECTION=database
INTERNAL_QUEUE_ENABLED=false
So all in all, I have two main questions:
-
Any idea how I can I make SMTP work with the Google SMTP Relay to fix the following error without resorting to using Sendmail:
Connection could not be established with host "smtp-relay.gmail.com:587": stream_socket_client(): Unable to connect to smtp-relay.gmail.com:587 (Network is unreachable)
? -
Any idea on how I can make sure my Laravel Supervisor service is doing its job (because clearly, it isn’t and I used to have more success by running the queue:work command in a cron job on my previous server)? Here is my
laravel-worker.conf
, if that helps:
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /home/charleso/public_html/admin/artisan queue:work sqs --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=charleso
numprocs=2
redirect_stderr=true
stdout_logfile=/home/charleso/public_html/admin/laravel_worker.log
stopwaitsecs=3600
And here is what I get when asking the system for the Supervisor status:
# systemctl status supervisor
● supervisor.service - Supervisor process control system for UNIX
Loaded: loaded (/lib/systemd/system/supervisor.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2023-01-15 21:59:14 EST; 20h ago
Docs: http://supervisord.org
Main PID: 446 (supervisord)
Tasks: 3 (limit: 231998)
Memory: 155.8M
CGroup: /system.slice/supervisor.service
├─ 446 /usr/bin/python3 /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
├─219909 /opt/cpanel/ea-php81/root/usr/bin/php /home/charleso/public_html/admin/artisan queue:work sqs --sleep=3 --tries=3 --max-time=3600
└─220008 /opt/cpanel/ea-php81/root/usr/bin/php /home/charleso/public_html/admin/artisan queue:work sqs --sleep=3 --tries=3 --max-time=3600
Thanks in advance!