API - port can be omitted in EMAIL_URL (defaults to 25)

This commit is contained in:
Sam 2022-01-01 11:27:16 +01:00
parent 33fde0394a
commit d17626c301
6 changed files with 22 additions and 7 deletions

View File

@ -209,9 +209,11 @@ To send emails, a valid ``EMAIL_URL`` must be provided:
- with SSL: ``smtp://username:password@smtp.example.com:465/?ssl=True``
- with STARTTLS: ``smtp://username:password@smtp.example.com:587/?tls=True``
.. versionadded:: 0.5.3
Credentials can be omitted: ``smtp://smtp.example.com:25``
| Credentials can be omitted: ``smtp://smtp.example.com:25``.
| If ``:<port>`` is omitted, the port defaults to 25.
Map tile server
^^^^^^^^^^^^^^^

View File

@ -461,7 +461,10 @@ see <a class="reference external" href="https://docs.sqlalchemy.org/en/13/core/p
<div class="versionadded">
<p><span class="versionmodified added">New in version 0.5.3.</span></p>
</div>
<p>Credentials can be omitted: <code class="docutils literal notranslate"><span class="pre">smtp://smtp.example.com:25</span></code></p>
<div class="line-block">
<div class="line">Credentials can be omitted: <code class="docutils literal notranslate"><span class="pre">smtp://smtp.example.com:25</span></code>.</div>
<div class="line">If <code class="docutils literal notranslate"><span class="pre">:&lt;port&gt;</span></code> is omitted, the port defaults to 25.</div>
</div>
</section>
<section id="map-tile-server">
<h3>Map tile server<a class="headerlink" href="#map-tile-server" title="Permalink to this headline"></a></h3>

View File

@ -209,9 +209,11 @@ To send emails, a valid ``EMAIL_URL`` must be provided:
- with SSL: ``smtp://username:password@smtp.example.com:465/?ssl=True``
- with STARTTLS: ``smtp://username:password@smtp.example.com:587/?tls=True``
.. versionadded:: 0.5.3
Credentials can be omitted: ``smtp://smtp.example.com:25``
| Credentials can be omitted: ``smtp://smtp.example.com:25``.
| If ``:<port>`` is omitted, the port defaults to 25.
Map tile server
^^^^^^^^^^^^^^^

View File

@ -69,7 +69,7 @@ class EmailTemplate:
class Email:
def __init__(self, app: Optional[Flask] = None) -> None:
self.host = 'localhost'
self.port = 1025
self.port = 25
self.use_tls = False
self.use_ssl = False
self.username = None

View File

@ -14,7 +14,7 @@ def parse_email_url(email_url: str) -> Dict:
)
return {
'host': parsed_url.host,
'port': parsed_url.port,
'port': 25 if parsed_url.port is None else parsed_url.port,
'use_tls': True if parsed_url.query == 'tls=True' else False,
'use_ssl': True if parsed_url.query == 'ssl=True' else False,
'username': credentials[0],

View File

@ -12,8 +12,8 @@ class TestEmailUrlParser:
with pytest.raises(InvalidEmailUrlScheme):
parse_email_url(url)
def test_it_parses_email_url_without_authentication(self) -> None:
url = 'smtp://localhost:25'
@staticmethod
def assert_parsed_email(url: str) -> None:
parsed_email = parse_email_url(url)
assert parsed_email['username'] is None
assert parsed_email['password'] is None
@ -22,6 +22,14 @@ class TestEmailUrlParser:
assert parsed_email['use_tls'] is False
assert parsed_email['use_ssl'] is False
def test_it_parses_email_url_without_port(self) -> None:
url = 'smtp://localhost'
self.assert_parsed_email(url)
def test_it_parses_email_url_without_authentication(self) -> None:
url = 'smtp://localhost:25'
self.assert_parsed_email(url)
def test_it_parses_email_url(self) -> None:
url = 'smtp://test@example.com:12345678@localhost:25'
parsed_email = parse_email_url(url)