Browse Source

Email plugin allows no auth and added smtp_server detection (#214)

pull/219/head
Chris Caron 5 years ago committed by GitHub
parent
commit
44905e5c6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      apprise/plugins/NotifyEmail.py
  2. 5
      test/test_email_plugin.py

25
apprise/plugins/NotifyEmail.py

@ -269,6 +269,14 @@ class NotifyEmail(NotifyBase):
# Define object templates # Define object templates
templates = ( templates = (
'{schema}://{host}',
'{schema}://{host}:{port}',
'{schema}://{host}/{targets}',
'{schema}://{host}:{port}/{targets}',
'{schema}://{user}@{host}',
'{schema}://{user}@{host}:{port}',
'{schema}://{user}@{host}/{targets}',
'{schema}://{user}@{host}:{port}/{targets}',
'{schema}://{user}:{password}@{host}', '{schema}://{user}:{password}@{host}',
'{schema}://{user}:{password}@{host}:{port}', '{schema}://{user}:{password}@{host}:{port}',
'{schema}://{user}:{password}@{host}/{targets}', '{schema}://{user}:{password}@{host}/{targets}',
@ -280,13 +288,11 @@ class NotifyEmail(NotifyBase):
'user': { 'user': {
'name': _('User Name'), 'name': _('User Name'),
'type': 'string', 'type': 'string',
'required': True,
}, },
'password': { 'password': {
'name': _('Password'), 'name': _('Password'),
'type': 'string', 'type': 'string',
'private': True, 'private': True,
'required': True,
}, },
'host': { 'host': {
'name': _('Domain'), 'name': _('Domain'),
@ -388,7 +394,7 @@ class NotifyEmail(NotifyBase):
self.from_name = from_name self.from_name = from_name
self.from_addr = from_addr self.from_addr = from_addr
if not self.from_addr: if self.user and not self.from_addr:
# detect our email address # detect our email address
self.from_addr = '{}@{}'.format( self.from_addr = '{}@{}'.format(
re.split(r'[\s@]+', self.user)[0], re.split(r'[\s@]+', self.user)[0],
@ -446,6 +452,10 @@ class NotifyEmail(NotifyBase):
# Apply any defaults based on certain known configurations # Apply any defaults based on certain known configurations
self.NotifyEmailDefaults() self.NotifyEmailDefaults()
# if there is still no smtp_host then we fall back to the hostname
if not self.smtp_host:
self.smtp_host = self.host
return return
def NotifyEmailDefaults(self): def NotifyEmailDefaults(self):
@ -454,10 +464,11 @@ class NotifyEmail(NotifyBase):
it was provided. it was provided.
""" """
if self.smtp_host: if self.smtp_host or not self.user:
# SMTP Server was explicitly specified, therefore it is assumed # SMTP Server was explicitly specified, therefore it is assumed
# the caller knows what he's doing and is intentionally # the caller knows what he's doing and is intentionally
# over-riding any smarts to be applied # over-riding any smarts to be applied. We also can not apply
# any default if there was no user specified.
return return
# detect our email address using our user/host combo # detect our email address using our user/host combo
@ -683,7 +694,7 @@ class NotifyEmail(NotifyBase):
args['bcc'] = ','.join(self.bcc) args['bcc'] = ','.join(self.bcc)
# pull email suffix from username (if present) # pull email suffix from username (if present)
user = self.user.split('@')[0] user = None if not self.user else self.user.split('@')[0]
# Determine Authentication # Determine Authentication
auth = '' auth = ''
@ -693,7 +704,7 @@ class NotifyEmail(NotifyBase):
password=self.pprint( password=self.pprint(
self.password, privacy, mode=PrivacyMode.Secret, safe=''), self.password, privacy, mode=PrivacyMode.Secret, safe=''),
) )
else: elif user:
# user url # user url
auth = '{user}@'.format( auth = '{user}@'.format(
user=NotifyEmail.quote(user, safe=''), user=NotifyEmail.quote(user, safe=''),

5
test/test_email_plugin.py

@ -205,6 +205,11 @@ TEST_URLS = (
# is set and tests that we gracfully handle them # is set and tests that we gracfully handle them
'test_smtplib_exceptions': True, 'test_smtplib_exceptions': True,
}), }),
# Test no auth at all
('mailto://localhost?from=test@example.com&to=test@example.com', {
'instance': plugins.NotifyEmail,
'privacy_url': 'mailto://localhost',
}),
) )

Loading…
Cancel
Save