This commit is contained in:
gsinghpal
2026-05-25 20:11:03 -04:00
parent 67af54b46e
commit 5f372b462a
21 changed files with 444 additions and 833 deletions

View File

@@ -221,3 +221,30 @@ class ResUsers(models.Model):
'mfa': 'default',
}
return super()._check_credentials(credential, env)
# ------------------------------------------------------------------
# _fp_resolve_from_header — used by mail.template email_from / reply_to
# ------------------------------------------------------------------
# Picks the From address that matches the active outbound mail server's
# from_filter, so the message goes out perfectly aligned for SPF +
# DKIM + DMARC. Mismatched From triggers M365 greylisting (515 min
# delivery delay) on cross-provider mail — the user feels this as
# "the email takes a while." Mail-server lookups need sudo; the kiosk
# session calling the template has no read on ir.mail_server. Falls
# back to res.company.email if no usable mail server is configured.
def _fp_resolve_from_header(self):
self.ensure_one()
Server = self.env['ir.mail_server'].sudo()
srv = Server.search([('active', '=', True)],
order='sequence asc, id asc', limit=1)
if srv and srv.from_filter and '@' in srv.from_filter:
# from_filter can be 'user@domain' OR a domain like '*@domain' /
# 'domain' — only the exact-address form is safe to use as From.
ff = srv.from_filter.strip()
if not ff.startswith('*') and ' ' not in ff:
return ff
if srv and srv.smtp_user and '@' in srv.smtp_user:
return srv.smtp_user
# Last-ditch fallback — preserves the legacy behaviour for any
# environment that has no mail server configured.
return self.company_id.email or self.email or ''