System sent Mails not arriving, but User sent Mails work

I have made an interesting discovery that I have not yet found in any forum. I use Invoice Ninja “v5.8.33-C156” on Docker and have several companies in the application. 3 of them to be exact. I want to use a separate mail server with a separate sender for each of these 3 companies. I have made this possible with the ENV file by always adding the company ID and a sub-string in front of the variables (MAIL_ENCRYPTION, MAIL_FROM_ADDRESS, MAIL_FROM_NAME, MAIL_HOST, MAIL_PASSWORD, MAIL_PORT, MAIL_USERNAME), for example 1_MAIL_ENCRYPTION.

This also works relatively well. But today I noticed that automatic invoice dispatch no longer works. They are now sent from [email protected] instead of the correct email address and therefore no longer reach the customer. This also happens when I want to create new users and they receive a confirmation email. This is sent from [email protected] instead of the correct email address in the ENV file.

The strange thing is, when i manually send invoices, they arrive like a charm with the correct mail sender.

My question now is, how can I fix this error? I would like to run all 3 companies in one Invoice Ninja instance, but in a way that it works and I can use a separate SMTP provider for all 3 companies.

I would be very grateful for any help as I love using Invoice Ninja and supporting it!

This is my ENV:

# IN application vars
APP_URL=https://XXX
APP_KEY=XXX
APP_DEBUG=false
REQUIRE_HTTPS=true
PHANTOMJS_PDF_GENERATION=false
PDF_GENERATOR=snappdf
TRUSTED_PROXIES='*'

QUEUE_CONNECTION=database

# DB connection
DB_HOST=db
DB_PORT=3306
DB_DATABASE=ninja
DB_USERNAME=XXX
DB_PASSWORD=XXX

# Create initial user
# Default to these values if empty
# [email protected]
# IN_PASSWORD=changeme!
IN_USER_EMAIL=XXX
IN_PASSWORD=XXX

# Mail options

MAIL_MAILER=smtp

# First Company
1_MAIL_HOST=mail.XXX
1_MAIL_PORT=587
1_MAIL_USERNAME=no-reply@XXX1
1_MAIL_PASSWORD=XXX
1_MAIL_ENCRYPTION=STARTTLS
1_MAIL_FROM_ADDRESS='XXX'
1_MAIL_FROM_NAME='XXX'

# Second Company
4_MAIL_HOST=mail.XXX
4_MAIL_PORT=587
4_MAIL_USERNAME=no-reply@XXX2
4_MAIL_PASSWORD=XXX
4_MAIL_ENCRYPTION=STARTTLS
4_MAIL_FROM_ADDRESS='XXX'
4_MAIL_FROM_NAME='XXX'

# Third Company
7_MAIL_HOST=mail.XXX
7_MAIL_PORT=587
7_MAIL_USERNAME=no-reply@XXX3
7_MAIL_PASSWORD=XXX
7_MAIL_ENCRYPTION=STARTTLS
7_MAIL_FROM_ADDRESS='XXX'
7_MAIL_FROM_NAME='XXX'

# MySQL
MYSQL_ROOT_PASSWORD=XXX
MYSQL_USER=XXX
MYSQL_PASSWORD=XXX
MYSQL_DATABASE=ninja

# V4 env vars
# DB_STRICT=false
# APP_CIPHER=AES-256-CBC

And as i said, if I add a “normal” mail block as shown below, everything works (but all 3 companies are then on one smtp sender)

MAIL_HOST=mail.XXX
MAIL_PORT=587
MAIL_USERNAME=no-reply@XXX1
MAIL_PASSWORD=XXX
MAIL_ENCRYPTION=STARTTLS
MAIL_FROM_ADDRESS='XXX'
MAIL_FROM_NAME='XXX'

Many thanks and best regards
Noah

Hi,

If you think this is a bug please create an issue on GitHub.

Note: in the latest version of the app it’s now possible to configure the company SMTP credentials on Settings > Email Settings.

Hey Hillel

oh my god, this is exactly the feature I’ve always missed in Invoice Ninja! I’ll test it straight away and if it works, I won’t need to use the ENV (1_, 2_, …) at all. That would really be the highlight of the day!

I have now found the function in the settings. Can I now delete the 3 email blocks from my ENV file, or do I still need to have the original SMTP block in the ENV file?

Thank you very much for the quick feedback!

I believe you can remove the extra .env parameters.

i have now removed all email settings from the env file, recreated the docker and emptied the cache.
if i now enter the data in the smtp settings and send a test mail (using the test mail button), the mail is sent to my Invoice Ninja email user, but the sender is [email protected].

when i save the smtp settings and create an invoice and want to send it to an email address of mine, it does not arrive, although according to invoice ninja the mail has been sent. so i don’t see any errors, nothing is logged. i assume that the mail is sent as [email protected] again and therefore does not end up in my mailbox.

now i have reinserted the standard smtp block in the env file and added my main data. but now all mails are sent via this data again, no matter what is set in the smtp settings of the companies. the mails are only sent via this address.

Am I doing something wrong? what do I have to set in the ENV file so that the SMTP settings of the Invoice Ninja application take effect?

@david any ideas where [email protected] is coming from?

FYI… in the latest version of the app you can configure per company SMTP settings on Settings > Email Settings.

@david I noticed [email protected] is the default value if the .env value isn’t set.

1 Like

@hillel

Thats correct. the mailer will also fail completely with blank strings for these two particular values.

Hey!

Thank you for your input. I assume that you also use several companies and several mail servers / mail accounts (because of 2_MAIL…). Do the automatic invoices work normally for you, or are they also sent as [email protected]? The same with user verification mails, for example.

I have also changed the mail settings in the IN app to default again and specified the mail data in the ENV file. I have also added the variable X_MAIL_EHLO_DOMAIN… but the mails that are sent directly from the system (automatic invoices, user verifications) are still sent from hello@example. I have emptied the cache.

That will probably be the problem. The array should also be able to respond to the individual companies (1_, 2_, …) so that the mails sent by the system are also sent by the correct sender.

Is there a way to do this? Could this code block perhaps be removed and it would work? Would probably be too easy, I guess :wink:

Are you configuring the SMTP values with the .env variables or using the app on Settings > Email Settings?

I suggest trying to configure the SMTP values in the app to see if it helps.

@david should we remove this section from the docs?

What do you use for your smtp server?

Enabling DEBUG mode and Expanded logging might help - Free Source Available Invoicing, Expenses & Time-Tracking | Invoice Ninja

Yes, we’ll need to update the setup page to insert the SMTP details into the company table rather than .env

After that we can update the docs to match

@hillel

However, if I only set the SMTP settings in the IN app and remove everything that has to do with mail from the ENV file, then system notifications such as the verification of a new user or the automatic sending of invoices are sent as [email protected], and not from the address that I have defined in the IN app.
This only works for invoices or offers that I send to a customer myself. there it works without any problems. but I would like the emails sent by the system to also be taken into account by these IN settings.
am i the only one who has this problem? i have tried many variations and each time i have recreated the container and cleared the cache.

@david any thoughts?

@eyer2003

I’ll tag another release which does have a change around the the From name calculation. Please update if the issue persists.

My first comment :wink:
I have the same issue.
Manual sending with env settings works fine - Recurring Invoice sending fails.

When I changed the mailsettings to “Settings-E-Mail-SMTP” and insert all data here,
my “FROM” email address is used from my user-account.
The mailserver is rejecting this MAIL-FROM Name:

553 5.7.1 [email protected]: Sender address rejected: not owned by user rechnung@***companydomain.de;

How we can solve this issue?

@andi_d Are you using the flutter front end or react? I believe the issue may be that the SMTP config in the flutter application is missing the from email field