mirror of
https://github.com/home-assistant/core.git
synced 2025-04-27 18:57:57 +00:00
Use voluptuous for smtp (#3048)
Make note of the breaking change in release notes
This commit is contained in:
parent
c1794d111e
commit
4e044361c3
@ -10,31 +10,46 @@ from email.mime.multipart import MIMEMultipart
|
|||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
from email.mime.image import MIMEImage
|
from email.mime.image import MIMEImage
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.components.notify import (
|
from homeassistant.components.notify import (
|
||||||
ATTR_TITLE, ATTR_DATA, DOMAIN, BaseNotificationService)
|
ATTR_TITLE, ATTR_DATA, PLATFORM_SCHEMA, BaseNotificationService)
|
||||||
from homeassistant.helpers import validate_config
|
from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD, CONF_PORT)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
ATTR_IMAGES = 'images' # optional embedded image file attachments
|
ATTR_IMAGES = 'images' # optional embedded image file attachments
|
||||||
|
|
||||||
|
CONF_STARTTLS = 'starttls'
|
||||||
|
CONF_SENDER = 'sender'
|
||||||
|
CONF_RECIPIENT = 'recipient'
|
||||||
|
CONF_DEBUG = 'debug'
|
||||||
|
CONF_SERVER = 'server'
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Required(CONF_RECIPIENT): cv.string,
|
||||||
|
vol.Optional(CONF_SERVER, default='localhost'): cv.string,
|
||||||
|
vol.Optional(CONF_PORT, default=25): cv.port,
|
||||||
|
vol.Optional(CONF_SENDER): cv.string,
|
||||||
|
vol.Optional(CONF_STARTTLS, default=False): cv.boolean,
|
||||||
|
vol.Optional(CONF_USERNAME): cv.string,
|
||||||
|
vol.Optional(CONF_PASSWORD): cv.string,
|
||||||
|
vol.Optional(CONF_DEBUG, default=False): cv.boolean,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def get_service(hass, config):
|
def get_service(hass, config):
|
||||||
"""Get the mail notification service."""
|
"""Get the mail notification service."""
|
||||||
if not validate_config({DOMAIN: config},
|
|
||||||
{DOMAIN: ['recipient']},
|
|
||||||
_LOGGER):
|
|
||||||
return None
|
|
||||||
|
|
||||||
mail_service = MailNotificationService(
|
mail_service = MailNotificationService(
|
||||||
config.get('server', 'localhost'),
|
config.get(CONF_SERVER),
|
||||||
int(config.get('port', '25')),
|
config.get(CONF_PORT),
|
||||||
config.get('sender', None),
|
config.get(CONF_SENDER),
|
||||||
int(config.get('starttls', 0)),
|
config.get(CONF_STARTTLS),
|
||||||
config.get('username', None),
|
config.get(CONF_USERNAME),
|
||||||
config.get('password', None),
|
config.get(CONF_PASSWORD),
|
||||||
config.get('recipient', None),
|
config.get(CONF_RECIPIENT),
|
||||||
config.get('debug', 0))
|
config.get(CONF_DEBUG))
|
||||||
|
|
||||||
if mail_service.connection_is_valid():
|
if mail_service.connection_is_valid():
|
||||||
return mail_service
|
return mail_service
|
||||||
@ -65,7 +80,7 @@ class MailNotificationService(BaseNotificationService):
|
|||||||
mail = smtplib.SMTP(self._server, self._port, timeout=5)
|
mail = smtplib.SMTP(self._server, self._port, timeout=5)
|
||||||
mail.set_debuglevel(self.debug)
|
mail.set_debuglevel(self.debug)
|
||||||
mail.ehlo_or_helo_if_needed()
|
mail.ehlo_or_helo_if_needed()
|
||||||
if self.starttls == 1:
|
if self.starttls:
|
||||||
mail.starttls()
|
mail.starttls()
|
||||||
mail.ehlo()
|
mail.ehlo()
|
||||||
if self.username and self.password:
|
if self.username and self.password:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user