Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Email notifications #242

Open
wants to merge 2 commits into from

4 participants

@ivanfilippov

Working implementation of email notifications on non-secure SMTP server. Addresses Google Code issue #1911 (http://code.google.com/p/sickbeard/issues/detail?id=1191)

@ghost

Please implement this!

@icovada

Magnificent, exactly what I was looking for.
Let us not forget good old email

@xombiemp

Does this work using Gmail as the SMTP server? I'm guessing not because you state "on non-secure SMTP server".

@ivanfilippov

It doesn't work on servers with SSL/TLS security like the ones Gmail provides. It should be trivial to add if this ever gets merged.

@xombiemp

You should add it now! I would love to see this get merged, and I think you'll have a better chance if it supports SSL/TLS.

@ivanfilippov

Good point xombiemp, I'll try to have a look at this next week, as I'm a bit busy for the next little while.

@gregsheremeta

This is still open? 2 years?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
BIN  data/images/notifiers/email.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
71 data/interfaces/default/config_notifications.tmpl
@@ -672,6 +672,77 @@
</div>
+ <div id="core-component-group11" class="component-group clearfix">
+ <div class="component-group-desc">
+ <h3><img src="$sbRoot/images/notifiers/email.gif" alt="Email" title="Email" width="16" height="16" />Email</h3>
+ <p>Send a simple email to an address of your choice.</p>
+ </div>
+
+ <fieldset class="component-group-list">
+ <div class="field-pair">
+ <input type="checkbox" class="enabler" name="use_email" id="use_email" #if $sickbeard.USE_EMAIL then "checked=\"checked\"" else ""# />
+ <label class="clearfix" for="use_email">
+ <span class="component-title">Enable</span>
+ <span class="component-desc">Should Sick Beard send notifications to an email address?<br /><br />
+ </span>
+ </label>
+ </div>
+ <div id="content_use_email">
+ <div class="field-pair">
+ <input type="checkbox" name="email_notify_onsnatch" id="email_notify_onsnatch" #if $sickbeard.EMAIL_NOTIFY_ONSNATCH then "checked=\"checked\"" else ""# />
+ <label class="clearfix" for="email_notify_onsnatch">
+ <span class="component-title">Notify on Snatch</span>
+ <span class="component-desc">Send notification when we start a download?</span>
+ </label>
+ </div>
+
+ <div class="field-pair">
+ <input type="checkbox" name="email_notify_ondownload" id="email_notify_ondownload" #if $sickbeard.EMAIL_NOTIFY_ONDOWNLOAD then "checked=\"checked\"" else ""# />
+ <label class="clearfix" for="email_notify_ondownload">
+ <span class="component-title">Notify on Download</span>
+ <span class="component-desc">Send notification when we finish a download?</span>
+ </label>
+ </div>
+ <div class="field-pair">
+ <label class="nocheck clearfix">
+ <span class="component-title">SMTP Server Address</span>
+ <input type="text" name="email_server" id="email_server" value="$sickbeard.EMAIL_SERVER" size="35" />
+ </label>
+ <label class="nocheck clearfix">
+ <span class="component-title">&nbsp;</span>
+ <span class="component-desc">SMTP Server IP Address or Hostname</span>
+ </label>
+ </div>
+
+ <div class="field-pair">
+ <label class="nocheck clearfix">
+ <span class="component-title">Sender Email Address</span>
+ <input type="text" name="email_sender" id="email_sender" value="$sickbeard.EMAIL_SENDER" size="35" />
+ </label>
+ <label class="nocheck clearfix">
+ <span class="component-title">&nbsp;</span>
+ <span class="component-desc">&nbsp;</span>
+ </label>
+ </div>
+
+ <div class="field-pair">
+ <label class="nocheck clearfix">
+ <span class="component-title">Recipient Email Address</span>
+ <input type="text" name="email_recipient" id="email_recipient" value="$sickbeard.EMAIL_RECIPIENT" size="35" />
+ </label>
+ <label class="nocheck clearfix">
+ <span class="component-title">&nbsp;</span>
+ <span class="component-desc">&nbsp;</span>
+ </label>
+ </div>
+
+ <div class="testNotification" id="testEmail-result">Click below to test.</div>
+ <input type="button" value="Test Email" id="testEmail" />
+ <input type="submit" class="config_submitter" value="Save Changes" />
+ </div><!-- /content_use_email //-->
+ </fieldset>
+ </div><!-- /component-group //-->
+
<br/><input type="submit" class="config_submitter" value="Save Changes" /><br/>
View
9 data/js/configNotifications.js
@@ -117,4 +117,13 @@ $(document).ready(function(){
$.get(sbRoot+"/home/testNMJ", {'host': nmj_host, 'database': nmj_database, 'mount': nmj_mount},
function (data){ $('#testNMJ-result').html(data); });
});
+
+ $('#testEmail').click(function(){
+ $('#testEmail-result').html(loading);
+ var email_server = $("#email_server").val();
+ var email_sender = $("#email_sender").val();
+ var email_recipient = $("#email_recipient").val();
+ $.get(sbRoot+"/home/testEmail", {'server': email_server, 'sender': email_sender, 'recipient': email_recipient},
+ function (data){ $('#testEmail-result').html(data); });
+ });
});
View
25 sickbeard/__init__.py
@@ -247,6 +247,13 @@
USE_SYNOINDEX = False
+USE_EMAIL = False
+EMAIL_NOTIFY_ONSNATCH = False
+EMAIL_NOTIFY_ONDOWNLOAD = False
+EMAIL_SERVER = None
+EMAIL_SENDER = None
+EMAIL_RECIPIENT = None
+
COMING_EPS_LAYOUT = None
COMING_EPS_DISPLAY_PAUSED = None
COMING_EPS_SORT = None
@@ -369,7 +376,8 @@ def initialize(consoleLogging=True):
NZBSRUS, NZBSRUS_UID, NZBSRUS_HASH, NAMING_QUALITY, providerList, newznabProviderList, \
NAMING_DATES, EXTRA_SCRIPTS, USE_TWITTER, TWITTER_USERNAME, TWITTER_PASSWORD, TWITTER_PREFIX, \
USE_NOTIFO, NOTIFO_USERNAME, NOTIFO_APISECRET, NOTIFO_NOTIFY_ONDOWNLOAD, NOTIFO_NOTIFY_ONSNATCH, \
- USE_BOXCAR, BOXCAR_USERNAME, BOXCAR_PASSWORD, BOXCAR_NOTIFY_ONDOWNLOAD, BOXCAR_NOTIFY_ONSNATCH, \
+ USE_BOXCAR, BOXCAR_USERNAME, BOXCAR_PASSWORD, BOXCAR_NOTIFY_ONDOWNLOAD, BOXCAR_NOTIFY_ONSNATCH, \
+ USE_EMAIL, EMAIL_SERVER, EMAIL_SENDER, EMAIL_RECIPIENT, EMAIL_NOTIFY_ONSNATCH, EMAIL_NOTIFY_ONDOWNLOAD, \
USE_LIBNOTIFY, LIBNOTIFY_NOTIFY_ONSNATCH, LIBNOTIFY_NOTIFY_ONDOWNLOAD, USE_NMJ, NMJ_HOST, NMJ_DATABASE, NMJ_MOUNT, USE_SYNOINDEX, \
USE_BANNER, USE_LISTVIEW, METADATA_XBMC, METADATA_MEDIABROWSER, METADATA_PS3, metadata_provider_dict, \
NEWZBIN, NEWZBIN_USERNAME, NEWZBIN_PASSWORD, GIT_PATH, MOVE_ASSOCIATED_FILES, \
@@ -585,6 +593,13 @@ def initialize(consoleLogging=True):
NMJ_DATABASE = check_setting_str(CFG, 'NMJ', 'nmj_database', '')
NMJ_MOUNT = check_setting_str(CFG, 'NMJ', 'nmj_mount', '')
+ USE_EMAIL = bool(check_setting_int(CFG, 'Email', 'use_email', 0))
+ EMAIL_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, 'Email', 'email_notify_onsnatch', 0))
+ EMAIL_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, 'Email', 'email_notify_ondownload', 0))
+ EMAIL_SERVER = check_setting_str(CFG, 'Email', 'email_server', '')
+ EMAIL_SENDER = check_setting_str(CFG, 'Email', 'email_sender', '')
+ EMAIL_RECIPIENT = check_setting_str(CFG, 'Email', 'email_recipient', '')
+
USE_SYNOINDEX = bool(check_setting_int(CFG, 'Synology', 'use_synoindex', 0))
GIT_PATH = check_setting_str(CFG, 'General', 'git_path', '')
@@ -1088,6 +1103,14 @@ def save_config():
new_config['NMJ']['nmj_database'] = NMJ_DATABASE
new_config['NMJ']['nmj_mount'] = NMJ_MOUNT
+ new_config['Email'] = {}
+ new_config['Email']['use_email'] = int(USE_EMAIL)
+ new_config['Email']['email_notify_onsnatch'] = int(EMAIL_NOTIFY_ONSNATCH)
+ new_config['Email']['email_notify_ondownload'] = int(EMAIL_NOTIFY_ONDOWNLOAD)
+ new_config['Email']['email_server'] = EMAIL_SERVER
+ new_config['Email']['email_sender'] = EMAIL_SENDER
+ new_config['Email']['email_recipient'] = EMAIL_RECIPIENT
+
new_config['Synology'] = {}
new_config['Synology']['use_synoindex'] = int(USE_SYNOINDEX)
View
5 sickbeard/notifiers/__init__.py
@@ -28,6 +28,7 @@
import boxcar
import nmj
import synoindex
+import email
from sickbeard.common import *
@@ -41,6 +42,7 @@
libnotify_notifier = libnotify.LibnotifyNotifier()
nmj_notifier = nmj.NMJNotifier()
synoindex_notifier = synoindex.synoIndexNotifier()
+email_notifier = email.EmailNotifier()
notifiers = [
# Libnotify notifier goes first because it doesn't involve blocking on
@@ -53,7 +55,8 @@
twitter_notifier,
nmj_notifier,
synoindex_notifier,
- boxcar_notifier
+ boxcar_notifier,
+ email_notifier
]
def notify_download(ep_name):
View
75 sickbeard/notifiers/email.py
@@ -0,0 +1,75 @@
+# Author: Ivan Filippov <ivan.v.f@gmail.com>
+# URL: http://code.google.com/p/sickbeard/
+#
+# This file is part of Sick Beard.
+#
+# Sick Beard is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Sick Beard is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.
+
+import smtplib
+import string
+
+import sickbeard
+
+from sickbeard import logger
+
+class EmailNotifier:
+
+ def test_notify(self, server, sender, recipient):
+ title = "Test:"
+ return self._sendEmail("This is a test notification from SickBeard", title, server, sender, recipient)
+
+ def _sendEmail(self, msg, title, server, sender, recipient):
+
+ email = string.join((
+ "From: %s" % sender,
+ "To: %s" % recipient,
+ "Subject: [Sick-Beard] %s" % title,
+ "",
+ msg
+ ), "\r\n")
+
+ try:
+ smtp = smtplib.SMTP(server)
+ smtp.sendmail(sender,recipient,email)
+ smtp.quit()
+ except (smtplib.socket.error, smtplib.SMTPException):
+ return False
+
+ return True
+
+ def notify_snatch(self, ep_name, title="Snatched:"):
+ if sickbeard.EMAIL_NOTIFY_ONSNATCH:
+ self._notifyEmail(title, ep_name)
+
+ def notify_download(self, ep_name, title="Completed:"):
+ if sickbeard.EMAIL_NOTIFY_ONDOWNLOAD:
+ self._notifyEmail(title, ep_name)
+
+ def _notifyEmail(self, title, message, server=None, sender=None, recipient=None, force=False):
+ if not sickbeard.USE_EMAIL and not force:
+ logger.log("Notification for Email not enabled, skipping this notification", logger.DEBUG)
+ return False
+ if not sender:
+ sender = sickbeard.EMAIL_SENDER
+ if not recipient:
+ recipient = sickbeard.EMAIL_RECIPIENT
+ if not server:
+ server = sickbeard.EMAIL_SERVER
+
+ self._sendEmail(message, title, server, sender, recipient)
+
+ logger.log(u"Sending email notification for " + message, logger.DEBUG)
+ return True
+
+notifier = EmailNotifier
View
33 sickbeard/webserve.py
@@ -1139,7 +1139,8 @@ def saveNotifications(self, use_xbmc=None, xbmc_notify_onsnatch=None, xbmc_notif
use_notifo=None, notifo_notify_onsnatch=None, notifo_notify_ondownload=None, notifo_username=None, notifo_apisecret=None,
use_boxcar=None, boxcar_notify_onsnatch=None, boxcar_notify_ondownload=None, boxcar_username=None,
use_libnotify=None, libnotify_notify_onsnatch=None, libnotify_notify_ondownload=None,
- use_nmj=None, nmj_host=None, nmj_database=None, nmj_mount=None, use_synoindex=None):
+ use_nmj=None, nmj_host=None, nmj_database=None, nmj_mount=None, use_synoindex=None,
+ use_email=None, email_notify_onsnatch=None, email_notify_ondownload=None, email_server=None, email_sender=None, email_recipient=None):
results = []
@@ -1264,6 +1265,20 @@ def saveNotifications(self, use_xbmc=None, xbmc_notify_onsnatch=None, xbmc_notif
else:
use_nmj = 0
+ if email_notify_onsnatch == "on":
+ email_notify_onsnatch = 1
+ else:
+ email_notify_onsnatch = 0
+
+ if email_notify_ondownload == "on":
+ email_notify_ondownload = 1
+ else:
+ email_notify_ondownload = 0
+ if use_email == "on":
+ use_email = 1
+ else:
+ use_email = 0
+
if use_synoindex == "on":
use_synoindex = 1
else:
@@ -1323,6 +1338,13 @@ def saveNotifications(self, use_xbmc=None, xbmc_notify_onsnatch=None, xbmc_notif
sickbeard.NMJ_DATABASE = nmj_database
sickbeard.NMJ_MOUNT = nmj_mount
+ sickbeard.USE_EMAIL = use_email
+ sickbeard.EMAIL_NOTIFY_ONSNATCH = email_notify_onsnatch
+ sickbeard.EMAIL_NOTIFY_ONDOWNLOAD = email_notify_ondownload
+ sickbeard.EMAIL_SERVER = email_server
+ sickbeard.EMAIL_SENDER = email_sender
+ sickbeard.EMAIL_RECIPIENT = email_recipient
+
sickbeard.USE_SYNOINDEX = use_synoindex
sickbeard.save_config()
@@ -1962,6 +1984,15 @@ def settingsNMJ(self, host=None):
else:
return '{"message": "Failed! Make sure your Popcorn is on and NMJ is running. (see Log & Errors -> Debug for detailed info)", "database": "", "mount": ""}'
+ @cherrypy.expose
+ def testEmail(self, server=None, sender=None, recipient=None):
+ cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store"
+
+ result = notifiers.email_notifier.test_notify(server, sender, recipient)
+ if result:
+ return "Successfully sent email"
+ else:
+ return "Email sending failed"
@cherrypy.expose
def shutdown(self):
Something went wrong with that request. Please try again.