From db07e45df89f23dbfe078364d0e361b39dd138e5 Mon Sep 17 00:00:00 2001 From: CV Date: Tue, 19 Mar 2019 22:37:12 +0100 Subject: [PATCH] Fix breaking on HTML email without images (#22143) * Fix breaking on HTML email without images If using html emails with no images the code breaks since it is not tested for empty (uninitialized) key images. * fixed long line * Implemented suggested better solution Better solution to allow data -> html email without images. * Protecting data -> without html key from crashing If the data key does not contain the html key, sending the email would crash this "script". Preventing this by returning an default empty array. --- homeassistant/components/notify/smtp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/notify/smtp.py b/homeassistant/components/notify/smtp.py index fc38647a065..e3a6f8b85b1 100644 --- a/homeassistant/components/notify/smtp.py +++ b/homeassistant/components/notify/smtp.py @@ -151,10 +151,10 @@ class MailNotificationService(BaseNotificationService): if data: if ATTR_HTML in data: msg = _build_html_msg( - message, data[ATTR_HTML], images=data.get(ATTR_IMAGES)) + message, data[ATTR_HTML], images=data.get(ATTR_IMAGES, [])) else: msg = _build_multipart_msg( - message, images=data.get(ATTR_IMAGES)) + message, images=data.get(ATTR_IMAGES, [])) else: msg = _build_text_msg(message)