getgrav / grav-plugin-email

Grav Email Plugin
http://getgrav.org
MIT License
37 stars 29 forks source link

"User is not set" error in recent versions #178

Closed hughbris closed 2 months ago

hughbris commented 11 months ago

I think this is only happening in versions 4+ since you switched to Symfony mailer.

Recent sites I've installed with this plugin have had intermittent problems where I see Grav logs like 2023-08-01 04:28:40 [CRITICAL] User is not set. Does not seem to interfere with mail sending though, or site operation that I have noticed.

The main annoyance for me has been that it stops some CLI stuff working, particularly bin/grav cache-clear. Here is what I see there:

In AbstractTransportFactory.php line 46:                                                                                                                                

  User is not set.                                                                                                                                                      

cache [--invalidate] [--purge] [--all] [--assets-only] [--images-only] [--cache-only] [--tmp-only] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [--env [ENV]] [--lang [LANG]] [--] <command>

This has been hard to isolate so please let me know if I can provide more information to help reproduce it.

The error message and AbstractTransportFactory have only been found in this plugin. I removed this plugin and the vendor one (sendinblue) to test this and the error went away. Reinstated the plugins and it came back.

The error is happening with at least two mail provider plugins: sendinblue and mailjet, so I don't think it's those plugins specifically. I'm using their APIs. Everything updated.

rhukster commented 11 months ago

What does your email config look like (please redact sensitive information).

Also can you provide an example form or scenario that exhibits this issue so I can try to recreate it. ?

hughbris commented 11 months ago

Thank you.

Also can you provide an example form or scenario that exhibits this issue so I can try to recreate it. ?

There is no form exhibiting this behaviour. Mail is generated from a contact form successfully. Pretty textbook setup.

The error is only present in Grav logs and some CLI commands, at least cache-clear and I think other(s).

Configs

Site A

email.yaml:

from: webserver@example.com
from_name: A website
to: info@example.com
to_name: Website A
reply_to: alt@example.com
reply_to_name: Website email alt
mailer:
  engine: mailjet
content_type: text/html
debug: true # it's a dev install

email-mailjet.yaml:

enabled: true
transport: api
api_key: API_KEY_REDACTED
secret_key: SECRET_KEY_REDACTED

Site B

email.yaml:

from: website@example.com
from_name: "B website"
to: info@example.com
to_name: Website Owner
mailer:
  engine: sendinblue
content_type: text/html
debug: false # is an unlaunched prod site

email-sendinblue.yaml:

enabled: true
transport: api
access_key: ACCESS_KEY_REDACTED

Let me know if I can provide anything else.

rhukster commented 11 months ago

I can't recreate this with your maijet or sendinblue configruation. Can you look in your grav.log and see if there's more detail on where the error is happening?

Thanks.

hughbris commented 11 months ago

Thanks for trying to reproduce. Damn tho :/

bin/grav logviewer is one of the commands that work. I can't see anything in the logs. These are my logging settings just in case there's something I can set to log more: log.handler=file, errors.log=true.

I decided to test the other CLI commands bringing up this error, except server, new-project, sandbox. The only ones that brought up this error were page-system-validator, scheduler, and security.

I tested other CLI commands. bin/gpm and bin/plugin work fine except for bin/plugin email test-email ...

Hope that helps. Looks like I will be able to work around this problem easily by reverting to SMTP settings.

Just a wild idea: could this be related to having environment overrides? I use those too. My experience is that these env configs are merged opaquely by Grav by the time any plugin goes to use them.

The other mystery is why only some of my installs experience this. I can look harder for patterns there if need be.

hughbris commented 2 months ago

My pleasure to contribute.

rhukster commented 2 months ago

if you want to PM your account creds on discord, I can test again. but I don't have an active account with them anymore.