Added SMTP SSL/TLS support#7960
Conversation
| if self.ssltls: | ||
| mail = smtplib.SMTP_SSL(self._server, self._port, timeout=self._timeout) | ||
| else: | ||
| mail = smtplib.SMTP(self._server, self._port, timeout=self._timeout) |
| """Connect/authenticate to SMTP Server.""" | ||
| mail = smtplib.SMTP(self._server, self._port, timeout=self._timeout) | ||
| if self.ssltls: | ||
| mail = smtplib.SMTP_SSL(self._server, self._port, timeout=self._timeout) |
| """Implement the notification service for E-mail messages.""" | ||
|
|
||
| def __init__(self, server, port, timeout, sender, starttls, username, | ||
| def __init__(self, server, port, timeout, sender, starttls, ssltls, username, |
|
I think this is confusing: I wonder if a single
(I know it's much more work to make it like that :-) |
|
Totally agree, this is just a quick fix. It should not be possible to set the starttls and ssltls options to true simultaneously. |
|
I was thinking "auto" could work like this:
If that is too complicated, the first two should work for many users and the rest would have to specify "none" to confirm that they want unencrypted communication. |
|
In my understanding, the encryption type is not related to password authentication. So the security option could be any of:
And port would be optional, default depending on the security option. |
|
You can absolutely send your password in cleartext but it's a bad idea and I don't think we should encourage it (even if it is the current default). |
|
We could set the default security to ssltls and add a warning on the documentation about sending password on a non encrypted session. |
|
I don't think that's a good default, port 465 has been deprecated for 20 years. The standard these days is port 587 with STARTTLS. |
|
It seems STARTTLS is less secure than SSL/TLS, as it is subject to man-in-the-middle attacks, and depending on the client if encryption negotiation fails it may fallback to non-encrypted session. https://en.wikipedia.org/wiki/Opportunistic_TLS |
|
Commited new proposal with "encryption" option, defaults to ssltls, and port defaults to 465. automation:
trigger:
platform: homeassistant
event: start
action:
- service: notify.mail
data:
title: "HASSdev started"
message: "yep"
notify:
- name: mail
platform: smtp
server: !secret smtp_server
sender: !secret mail_alert
username: !secret mail_username
password: !secret mail_password
recipient: !secret mail_admin
encryption: ssltls
debug: true |
| if self.encryption == "ssltls": | ||
| mail = smtplib.SMTP_SSL(self._server, self._port, timeout=self._timeout) | ||
| elif self.encryption == "none" or self.encryption == "starttls": | ||
| mail = smtplib.SMTP(self._server, self._port, timeout=self._timeout) |
There was a problem hiding this comment.
line too long (80 > 79 characters)
| """Connect/authenticate to SMTP Server.""" | ||
| mail = smtplib.SMTP(self._server, self._port, timeout=self._timeout) | ||
| if self.encryption == "ssltls": | ||
| mail = smtplib.SMTP_SSL(self._server, self._port, timeout=self._timeout) |
There was a problem hiding this comment.
line too long (84 > 79 characters)
| vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port, | ||
| vol.Optional(CONF_TIMEOUT, default=DEFAULT_TIMEOUT): cv.positive_int, | ||
| vol.Optional(CONF_STARTTLS, default=DEFAULT_STARTTLS): cv.boolean, | ||
| vol.Optional(CONF_ENCRYPTION, default=DEFAULT_ENCRYPTION): cv.string, |
There was a problem hiding this comment.
We should limit the options to valid entries. See our validation docs.
| mail = smtplib.SMTP(self._server, self._port, timeout=self._timeout) | ||
| if self.encryption == "ssltls": | ||
| mail = smtplib.SMTP_SSL(self._server, self._port, timeout=self._timeout) | ||
| elif self.encryption == "none" or self.encryption == "starttls": |
There was a problem hiding this comment.
This could be an else as you are covering the the two other options.
| vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port, | ||
| vol.Optional(CONF_TIMEOUT, default=DEFAULT_TIMEOUT): cv.positive_int, | ||
| vol.Optional(CONF_STARTTLS, default=DEFAULT_STARTTLS): cv.boolean, | ||
| vol.Optional(CONF_ENCRYPTION, default=DEFAULT_ENCRYPTION): vol.In(['ssltls','starttls','none']), |
There was a problem hiding this comment.
line too long (100 > 79 characters)
missing whitespace after ','
|
Thanks. Now the component fails to load with a nice error message:
|
|
STARTTLS is not less secure than the deprecated SSL wrapping. True, it can be "depending on the client" but in this case the client is HA, so we could choose not to be vulnerable. |
* Added SMTP SSL/TLS support * added new encryption option * validation of encryption option * Fix lint issues * Rename var
Description:
I ran tox and had errors, not sure how to publish results, please help.
Related issue (if applicable): fixes #
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#2843
Example entry for
configuration.yaml(if applicable):Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
toxrun successfully. Your PR cannot be merged unless tests passREQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.If the code does not interact with devices:
toxrun successfully. Your PR cannot be merged unless tests pass