Skip to content

Commit

Permalink
Add optional sender name for SendGrid (home-assistant#21610)
Browse files Browse the repository at this point in the history
* Set "Home Assistant" as email sender name for SendGrid

* make sender name configurable

* sendgrid tweaks

* fix config
  • Loading branch information
srirams authored and rohankapoorcom committed Mar 3, 2019
1 parent fa938f5 commit 818776d
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions homeassistant/components/notify/sendgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,35 @@

_LOGGER = logging.getLogger(__name__)

CONF_SENDER_NAME = 'sender_name'

DEFAULT_SENDER_NAME = 'Home Assistant'

# pylint: disable=no-value-for-parameter
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_API_KEY): cv.string,
vol.Required(CONF_SENDER): vol.Email(),
vol.Required(CONF_RECIPIENT): vol.Email(),
vol.Optional(CONF_SENDER_NAME, default=DEFAULT_SENDER_NAME): cv.string,
})


def get_service(hass, config, discovery_info=None):
"""Get the SendGrid notification service."""
api_key = config.get(CONF_API_KEY)
sender = config.get(CONF_SENDER)
recipient = config.get(CONF_RECIPIENT)

return SendgridNotificationService(api_key, sender, recipient)
return SendgridNotificationService(config)


class SendgridNotificationService(BaseNotificationService):
"""Implementation the notification service for email via Sendgrid."""

def __init__(self, api_key, sender, recipient):
def __init__(self, config):
"""Initialize the service."""
from sendgrid import SendGridAPIClient

self.api_key = api_key
self.sender = sender
self.recipient = recipient
self.api_key = config[CONF_API_KEY]
self.sender = config[CONF_SENDER]
self.sender_name = config[CONF_SENDER_NAME]
self.recipient = config[CONF_RECIPIENT]

self._sg = SendGridAPIClient(apikey=self.api_key)

Expand All @@ -64,7 +66,8 @@ def send_message(self, message='', **kwargs):
}
],
"from": {
"email": self.sender
"email": self.sender,
"name": self.sender_name
},
"content": [
{
Expand Down

0 comments on commit 818776d

Please sign in to comment.