API - allow EMAIL_URL without authentication - fix #127

This commit is contained in:
Sam
2022-01-01 11:04:08 +01:00
parent 9e683653d8
commit 33fde0394a
10 changed files with 62 additions and 8 deletions

View File

@ -110,7 +110,8 @@ class Email:
with self.smtp(
self.host, self.port, **connection_params # type: ignore
) as smtp:
smtp.login(self.username, self.password) # type: ignore
if self.username and self.password:
smtp.login(self.username, self.password) # type: ignore
if self.use_tls:
smtp.starttls(context=context)
smtp.sendmail(self.sender_email, recipient, message.as_string())

View File

@ -9,7 +9,9 @@ def parse_email_url(email_url: str) -> Dict:
parsed_url = parse_url(email_url)
if parsed_url.scheme != 'smtp':
raise InvalidEmailUrlScheme()
credentials = parsed_url.auth.split(':')
credentials = (
parsed_url.auth.split(':') if parsed_url.auth else [None, None]
)
return {
'host': parsed_url.host,
'port': parsed_url.port,