Recurring invoices fail through cron/smtp-relay

Hi there,

I’ve done a fair bit of searching around but simply couldn’t find a solution and am at my wits end.

As per the title, I’m having issues getting my recurrig invoices to send out - sending them directly through the Send Invoice button works completely fine.

The cron is currently setup under the correct user as follows (with the correct path, obviously):

* * * * * cd /path/to/ninja && /usr/bin/php7.4 artisan schedule:run >> /path/to/log/cronlog 2>&1

The log file looks as follows:

No scheduled commands are ready to run.
[2021-06-28T14:55:02+00:00] Running scheduled command: App\Jobs\Util\SchedulerCheck
No scheduled commands are ready to run.
No scheduled commands are ready to run.
No scheduled commands are ready to run.
No scheduled commands are ready to run.
[2021-06-28T15:00:01+00:00] Running scheduled command: App\Jobs\Util\ReminderJob
[2021-06-28T15:00:01+00:00] Running scheduled command: App\Jobs\Cron\RecurringInvoicesCron
[2021-06-28T15:00:01+00:00] Running scheduled command: App\Jobs\Util\SchedulerCheck
No scheduled commands are ready to run.
No scheduled commands are ready to run.
No scheduled commands are ready to run.
No scheduled commands are ready to run.
[2021-06-28T15:05:01+00:00] Running scheduled command: App\Jobs\Util\SchedulerCheck
No scheduled commands are ready to run.
No scheduled commands are ready to run.
No scheduled commands are ready to run.

And no errors in the /storage/logs/laravel.log

I’ve tried various cron permutations as explained
here
and here
with absolute paths, just using php7.4, etc.

I’m self hosting on Ubuntu 20.04 on the google cloud on a billing.example subdomain - this requires using the smtp-relay, which is configured to allow emails being sent from my server’s ip address (and are known to work, as long as they are sent manually and not through cron).

When the cronjob fires I’ll receive this error:
System failed to email invoice x
Expected Response code 250 but got an empty response

which happens on smpt relay without the SERVER_NAME= variable being set in the .env file.

At first I didn’t know what to put inside this variable, so I tried leaving it blank as well as using the domain I’m hosting it on, to no avail. I suspect this could be where my troubles are coming from.

Every google search has led me to believe there is something wrong with either my .env or relay email configuration, but I’m completely stumped as the emails work fine when being sent manually from the invoice ninja interface.

These are my settings, which I have checked over and over:

the ip address is correct and I have attempted it with TLS Require Encryption - the variables MAIL_USERNAME and MAIL_PASSWORD are blank as Require SMTP Authentication is disabled in my relay settings. And again, these all work just fine when manually sending emails through Invoice Ninja.

Am I missing something glaringly obvious here or does anyone have any ideas?

@david do you have any thoughts?

You may find more specific logs from the email server in the system_logs table.

Not sure what else to suggest on this.

Unfortunately all I’m getting there is that same error message, expected response 250.

I’ve turned on debug mode but can’t really seem to find anything else in any of the logs that might be of help :neutral_face:

Update: Just came across this stackoverflow answer, that I can’t test until later Laravel SMTP sending email by queue receiving empty response - Stack Overflow

Just for anyone curious, I finally worked it out!

Not sure why the SERVER_NAME variable in the .env file isn’t helping, but for a workaround setting it directly in Providers/AppServiceProvider.php by adding this line inside the boot() function:

    //Email Fix
    $_SERVER["SERVER_NAME"] = "my.domain.com";

so that it looks like this

solved all my troubles :slight_smile:

someone with more insight might be able to explain why setting it in .env didn’t work.

Thanks for sharing the solution!

cc @david