Mercurial > libervia-backend
comparison sat/tools/common/email.py @ 3780:2c187445a3d3
tools (common/email): use `from_email` is specified, always set `email_sender_domain`
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 16 May 2022 13:03:53 +0200 |
parents | be6d91572633 |
children | 524856bd7b19 |
comparison
equal
deleted
inserted
replaced
3779:89b13b405b93 | 3780:2c187445a3d3 |
---|---|
41 @return (D): same as smtp.sendmail | 41 @return (D): same as smtp.sendmail |
42 """ | 42 """ |
43 if isinstance(to_emails, str): | 43 if isinstance(to_emails, str): |
44 to_emails = to_emails.split() | 44 to_emails = to_emails.split() |
45 email_host = tools_config.getConfig(config, None, "email_server") or "localhost" | 45 email_host = tools_config.getConfig(config, None, "email_server") or "localhost" |
46 email_from = tools_config.getConfig(config, None, "email_from") | 46 email_from = from_email or tools_config.getConfig(config, None, "email_from") |
47 | |
48 # we suppose that email domain and XMPP domain are identical | |
49 domain = tools_config.getConfig(config, None, "xmpp_domain") | |
50 if domain is None: | |
51 if email_from is not None: | |
52 domain = email_from.split("@", 1)[-1] | |
53 else: | |
54 domain = "example.net" | |
55 | |
47 if email_from is None: | 56 if email_from is None: |
48 # we suppose that email domain and XMPP domain are identical | |
49 domain = tools_config.getConfig(config, None, "xmpp_domain", "example.net") | |
50 email_from = "no_reply@" + domain | 57 email_from = "no_reply@" + domain |
51 email_sender_domain = tools_config.getConfig(config, None, "email_sender_domain") | 58 email_sender_domain = tools_config.getConfig( |
52 if email_sender_domain is None and smtp.DNSNAME == b"localhost.localdomain": | 59 config, None, "email_sender_domain", domain |
53 try: | 60 ) |
54 email_sender_domain = email_from.split('@')[1] | |
55 except IndexError: | |
56 log.warning( | |
57 "Can't set email_sender_domain domain du to invalid email_from: " | |
58 f"{email_from!r}") | |
59 email_port = int(tools_config.getConfig(config, None, "email_port", 25)) | 61 email_port = int(tools_config.getConfig(config, None, "email_port", 25)) |
60 email_username = tools_config.getConfig(config, None, "email_username") | 62 email_username = tools_config.getConfig(config, None, "email_username") |
61 email_password = tools_config.getConfig(config, None, "email_password") | 63 email_password = tools_config.getConfig(config, None, "email_password") |
62 email_auth = C.bool(tools_config.getConfig(config, None, "email_auth", C.BOOL_FALSE)) | 64 email_auth = C.bool(tools_config.getConfig(config, None, "email_auth", C.BOOL_FALSE)) |
63 email_starttls = C.bool(tools_config.getConfig(config, None, "email_starttls", | 65 email_starttls = C.bool(tools_config.getConfig(config, None, "email_starttls", |