diff --git a/apprise/plugins/NotifyEmail.py b/apprise/plugins/NotifyEmail.py index 3f6d14ce..efcd694c 100644 --- a/apprise/plugins/NotifyEmail.py +++ b/apprise/plugins/NotifyEmail.py @@ -383,9 +383,17 @@ class NotifyEmail(NotifyBase): }, }) + # Define any kwargs we're using + template_kwargs = { + 'headers': { + 'name': _('Email Header'), + 'prefix': '+', + }, + } + def __init__(self, smtp_host=None, from_name=None, from_addr=None, secure_mode=None, targets=None, cc=None, - bcc=None, **kwargs): + bcc=None, headers=None, **kwargs): """ Initialize Email Object @@ -414,6 +422,11 @@ class NotifyEmail(NotifyBase): # For tracking our email -> name lookups self.names = {} + self.headers = {} + if headers: + # Store our extra headers + self.headers.update(headers) + # Now we want to construct the To and From email # addresses from the URL provided self.from_addr = from_addr @@ -648,6 +661,11 @@ class NotifyEmail(NotifyBase): content = MIMEText(body, 'plain', 'utf-8') base = MIMEMultipart() if attach else content + + # Apply any provided custom headers + for k, v in self.headers.items(): + base[k] = Header(v, 'utf-8') + base['Subject'] = Header(title, 'utf-8') try: base['From'] = formataddr( @@ -767,6 +785,9 @@ class NotifyEmail(NotifyBase): 'user': self.user, } + # Append our headers into our parameters + params.update({'+{}'.format(k): v for k, v in self.headers.items()}) + # Extend our parameters params.update(self.url_parameters(privacy=privacy, *args, **kwargs)) @@ -891,4 +912,9 @@ class NotifyEmail(NotifyBase): results['from_addr'] = from_addr results['smtp_host'] = smtp_host + # Add our Meta Headers that the user can provide with their outbound + # emails + results['headers'] = {NotifyBase.unquote(x): NotifyBase.unquote(y) + for x, y in results['qsd+'].items()} + return results diff --git a/test/test_email_plugin.py b/test/test_email_plugin.py index a434c1a6..2b20b325 100644 --- a/test/test_email_plugin.py +++ b/test/test_email_plugin.py @@ -165,6 +165,11 @@ TEST_URLS = ( 'instance': plugins.NotifyEmail, }, ), + # headers + ('mailto://user:pass@localhost.localdomain' + '?+X-Customer-Campaign-ID=Apprise', { + 'instance': plugins.NotifyEmail, + }), # No Password ('mailtos://user:@nuxref.com', { 'instance': plugins.NotifyEmail,