Repository: paperless-ngx/paperless-ngx

Issue:
[BUG] SMTP config has no var for FROM
### Description

Sending email for a password reset fails (Server 500) because the email server rejects from address. Paperless-ngx is using a default "webmaster@localhost" as the FROM address while the account details are associated with a specific email.  It's either a case where a default from is being used with the defined account information, or the SMTP env variables are not being used and an anonymous email is trying to be sent.  It looks like it just isn't using the HOST_USER and HOST_PASSWORD vars, following documentation from: https://docs.paperless-ngx.com/configuration/#email-sending
The fact that some log entry is showing in the mail server logs indicates that some env are working.

### Steps to reproduce

Set env vars:
PAPERLESS_EMAIL_HOST = mx.somedomain.com
PAPERLESS_EMAIL_PORT = 587
PAPERLESS_EMAIL_HOST_USER = noreply@somedomain.com
PAPERLESS_EMAIL_HOST_PASSWORD = password123
PAPERLESS_EMAIL_USE_TLS = true

Attempt a password reset. 
Server errors (500) and no email sent.

### Webserver logs

```bash
This is the offending paperless log entry:
smtplib.SMTPRecipientsRefused: {'noreply@somedomain.com': (504, b'5.5.2 <webmaster@localhost>: Sender address rejected: need fully-qualified address')}

Mail logs show:
Dec  6 20:57:31 mx postfix/submission/smtpd[28578]: connect from USG-3P[192.168.1.1]
Dec  6 20:57:31 mx postfix/submission/smtpd[28578]: Anonymous TLS connection established from usg-3p[192.168.1.1]: TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
Dec  6 20:57:31 mx postfix/submission/smtpd[28578]: NOQUEUE: reject: RCPT from USG-3P[192.168.1.1]: 504 5.5.2 <webmaster@localhost>: Sender address rejected: need fully-qualified address; from=<webmaster@localhost> to=<pwdresetuser@someotherdomain.com> proto=ESMTP helo=<bc51be1374dd>
```


### Browser logs

```bash
NA
```


### Paperless-ngx version

2.1.0

### Host OS

official docker

### Installation method

Docker - official image

### Browser

Brave

### Configuration changes

Properly setting of the documented PAPERLESS_EMAIL* vars

### Other

_No response_


Discussion:
Those settings just correspond to the Django settings here: https://docs.djangoproject.com/en/4.2/topics/email/.  Which I assume just uses Python's smtplib.  As it appears to have connected to the host, i would suggest lookging at your email server configuration, which is what rejected the email.
I've got several server apps using this server to send these password reset emails and such and they work. I expect to see the "noreply@somedomain.com" address associated with the send attempts like I do with all my other apps, instead of a "webmaster@localhost" address. I'm a bit stumped since setting the email server env vars pass right thru to paperless but it doesn't look like the USER and PASSWORD are passed through. At first I thought this was another case where an app wasn't let me set the from address, like Ghost blog does, forcing a from address by building it dynamically but fails to build the right from address in the case of Ghost being at a subdomain. But I couldn't find any evidence in the mail server log that paperless tried to authenticate as "noreply@somedomain.com"...
Ah, I wonder if it is from https://docs.djangoproject.com/en/4.2/ref/settings/#default-from-email

Knowing nothing about email, would it ever be the case where the sender would _not_ match the host user?  Like a login by x, but sent by y?
Yes, I have definitely faced a situation where the app would get all the way authenticated, send the email and the email server on the send side would reject it because the "from" address didn't match the address of the sender account. That used to be a common spam technique: send emails as some other user. But this case, I can't tell if it's authenticating at all, which pushes me to think that it's not supplying the EMAIL_HOST_USER and _PASSWORD to the email server.

I was thinking it could be possible I don't have the env vars set right (wrong names or something) especially if it changed and the docs lagged. The paperless logs don't specify what user and pass (even redacted) it tried. I'm looking for the flag to increase log level.

Resolving patch:
diff --git a/src/paperless/settings.py b/src/paperless/settings.py
--- a/src/paperless/settings.py
+++ b/src/paperless/settings.py
@@ -1036,6 +1036,7 @@ def _get_nltk_language_setting(ocr_lang: str) -> Optional[str]:
 EMAIL_PORT: Final[int] = int(os.getenv("PAPERLESS_EMAIL_PORT", 25))
 EMAIL_HOST_USER: Final[str] = os.getenv("PAPERLESS_EMAIL_HOST_USER", "")
 EMAIL_HOST_PASSWORD: Final[str] = os.getenv("PAPERLESS_EMAIL_HOST_PASSWORD", "")
+DEFAULT_FROM_EMAIL: Final[str] = os.getenv("PAPERLESS_EMAIL_FROM", EMAIL_HOST_USER)
 EMAIL_USE_TLS: Final[bool] = __get_boolean("PAPERLESS_EMAIL_USE_TLS")
 EMAIL_USE_SSL: Final[bool] = __get_boolean("PAPERLESS_EMAIL_USE_SSL")
 EMAIL_SUBJECT_PREFIX: Final[str] = "[Paperless-ngx] "


Test patch: