mirror of
https://github.com/caronc/apprise.git
synced 2025-02-23 05:31:17 +01:00
Header/Meta support added to email plugin (#310)
This commit is contained in:
parent
68adae39d1
commit
53a8d046ce
@ -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,
|
def __init__(self, smtp_host=None, from_name=None,
|
||||||
from_addr=None, secure_mode=None, targets=None, cc=None,
|
from_addr=None, secure_mode=None, targets=None, cc=None,
|
||||||
bcc=None, **kwargs):
|
bcc=None, headers=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Initialize Email Object
|
Initialize Email Object
|
||||||
|
|
||||||
@ -414,6 +422,11 @@ class NotifyEmail(NotifyBase):
|
|||||||
# For tracking our email -> name lookups
|
# For tracking our email -> name lookups
|
||||||
self.names = {}
|
self.names = {}
|
||||||
|
|
||||||
|
self.headers = {}
|
||||||
|
if headers:
|
||||||
|
# Store our extra headers
|
||||||
|
self.headers.update(headers)
|
||||||
|
|
||||||
# Now we want to construct the To and From email
|
# Now we want to construct the To and From email
|
||||||
# addresses from the URL provided
|
# addresses from the URL provided
|
||||||
self.from_addr = from_addr
|
self.from_addr = from_addr
|
||||||
@ -648,6 +661,11 @@ class NotifyEmail(NotifyBase):
|
|||||||
content = MIMEText(body, 'plain', 'utf-8')
|
content = MIMEText(body, 'plain', 'utf-8')
|
||||||
|
|
||||||
base = MIMEMultipart() if attach else content
|
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')
|
base['Subject'] = Header(title, 'utf-8')
|
||||||
try:
|
try:
|
||||||
base['From'] = formataddr(
|
base['From'] = formataddr(
|
||||||
@ -767,6 +785,9 @@ class NotifyEmail(NotifyBase):
|
|||||||
'user': self.user,
|
'user': self.user,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Append our headers into our parameters
|
||||||
|
params.update({'+{}'.format(k): v for k, v in self.headers.items()})
|
||||||
|
|
||||||
# Extend our parameters
|
# Extend our parameters
|
||||||
params.update(self.url_parameters(privacy=privacy, *args, **kwargs))
|
params.update(self.url_parameters(privacy=privacy, *args, **kwargs))
|
||||||
|
|
||||||
@ -891,4 +912,9 @@ class NotifyEmail(NotifyBase):
|
|||||||
results['from_addr'] = from_addr
|
results['from_addr'] = from_addr
|
||||||
results['smtp_host'] = smtp_host
|
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
|
return results
|
||||||
|
@ -165,6 +165,11 @@ TEST_URLS = (
|
|||||||
'instance': plugins.NotifyEmail,
|
'instance': plugins.NotifyEmail,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
# headers
|
||||||
|
('mailto://user:pass@localhost.localdomain'
|
||||||
|
'?+X-Customer-Campaign-ID=Apprise', {
|
||||||
|
'instance': plugins.NotifyEmail,
|
||||||
|
}),
|
||||||
# No Password
|
# No Password
|
||||||
('mailtos://user:@nuxref.com', {
|
('mailtos://user:@nuxref.com', {
|
||||||
'instance': plugins.NotifyEmail,
|
'instance': plugins.NotifyEmail,
|
||||||
|
Loading…
Reference in New Issue
Block a user