mirror of https://github.com/evilhero/mylar
IMP: Added new basic email notifier
This commit is contained in:
parent
9fa7ceb709
commit
c573d0bc51
|
@ -1490,6 +1490,58 @@
|
|||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<h3><img src="interfaces/default/images/email.png" style="vertical-align: middle; margin: 3px; margin-top: -1px;" height="30" width="30"/>Email</h3>
|
||||
<div class="row checkbox">
|
||||
<input type="checkbox" name="email_enabled" id="email" value="1" ${config['email_enabled']} /><label>Enable Email Notifications</label>
|
||||
</div>
|
||||
<div id="emailoptions">
|
||||
<div class="row">
|
||||
<label>Sender address</label><input type="email" name="email_from" id="email_from" value="${config['email_from']}" size="50" maxlength="80" style="width: 18em">
|
||||
<small>sender@hostname</small>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Recipient address</label><input type="email" name="email_to" id="email_to" value="${config['email_to']}" size="50" maxlength="80" style="width: 18em">
|
||||
<small>destination@hostname</small>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>SMTP server</label><input type="text" name="email_server" id="email_server" value="${config['email_server']}" size="50">
|
||||
<small>Hostname or IP address of your SMTP server</small>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>SMTP port</label><input type="number" name="email_port" id="email_port" value="${config['email_port']}" size="5" style="width: 5em">
|
||||
<small>SMTP port - usually 25, 465 or 587</small>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>SMTP username</label><input type="text" name="email_user" id="email_user" value="${config['email_user']}" size="50">
|
||||
<small>Username for SMTP server authentication</small>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>SMTP password</label><input type="password" name="email_password" id="email_password" value="${config['email_password']}" size="50">
|
||||
<small>Password for SMTP server authentication</small>
|
||||
</div>
|
||||
<input type="radio" style="vertical-align: middle; margin: 3px; margin-top: -1px;" name="email_enc" id="email_raw" value="0" ${config['email_raw']} checked />No encryption
|
||||
<input type="radio" style="vertical-align: middle; margin: 3px; margin-top: -1px;" name="email_enc" id="email_ssl" value="1" ${config['email_ssl']} />Use SSL?
|
||||
<input type="radio" style="vertical-align: middle; margin: 3px; margin-top: -1px;" name="email_enc" id="email_tls" value="2" ${config['email_tls']} />Use TLS?
|
||||
<div class="row checkbox">
|
||||
<small>SMTP server requires TLS or SSL encryption?</small>
|
||||
</div>
|
||||
<div class="row checkbox">
|
||||
<input type="checkbox" name="email_ongrab" value="1" ${config['email_ongrab']} /><label>Notify on grab?</label>
|
||||
<small>Notify when comics are grabbed?</small>
|
||||
</div>
|
||||
<div class="row checkbox">
|
||||
<input type="checkbox" name="email_onpost" value="1" ${config['email_onpost']} /><label>Notify on post processing?</label>
|
||||
<small>Notify when comics are post processed?</small>
|
||||
</div>
|
||||
<div align="center" class="row">
|
||||
<img name="email_statusicon" id="email_statusicon" src="interfaces/default/images/successs.png" style="float:right;visibility:hidden;" height="20" width="20" />
|
||||
<input type="button" value="Test Email" id="email_test" style="float:center" /></br>
|
||||
<input type="text" name="emailstatus" style="text-align:center; font-size:11px;" id="emailstatus" size="55" DISABLED />
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -1763,6 +1815,26 @@
|
|||
}
|
||||
});
|
||||
|
||||
if ($("#email").is(":checked"))
|
||||
{
|
||||
$("#emailoptions").show();
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#emailoptions").hide();
|
||||
}
|
||||
|
||||
$("#email").click(function(){
|
||||
if ($("#email").is(":checked"))
|
||||
{
|
||||
$("#emailoptions").slideDown();
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#emailoptions").slideUp();
|
||||
}
|
||||
});
|
||||
|
||||
if ($("#boxcar").is(":checked"))
|
||||
{
|
||||
$("#boxcaroptions").show();
|
||||
|
@ -2467,6 +2539,37 @@
|
|||
$('#ajaxMsg').addClass('success').fadeIn().delay(3000).fadeOut();
|
||||
});
|
||||
|
||||
$('#email_test').click(function () {
|
||||
var imagechk = document.getElementById("email_statusicon");
|
||||
var emailfrom = document.getElementById("email_from").value;
|
||||
var emailto = document.getElementById("email_to").value;
|
||||
var emailsvr = document.getElementById("email_server").value;
|
||||
var emailport = document.getElementById("email_port").value;
|
||||
var emailuser = document.getElementById("email_user").value;
|
||||
var emailpass = document.getElementById("email_password").value;
|
||||
var emailenc = document.querySelector('input[name="email_enc"]:checked').value; // While this causes a browser crash if no radio button is checked, we're ok because we force the default to be checked in the form.
|
||||
$.get("testemail",
|
||||
{ emailfrom: emailfrom, emailto: emailto, emailsvr: emailsvr, emailport: emailport, emailuser: emailuser, emailpass: emailpass, emailenc: emailenc },
|
||||
function(data){
|
||||
if (data.error != undefined) {
|
||||
alert(data.error);
|
||||
return;
|
||||
}
|
||||
$('#emailstatus').val(data);
|
||||
$('#ajaxMsg').html("<div class='msg'><span class='ui-icon ui-icon-check'></span>"+data+"</div>");
|
||||
if ( data.indexOf("Successfully") > -1){
|
||||
imagechk.src = "";
|
||||
imagechk.src = "interfaces/default/images/success.png";
|
||||
imagechk.style.visibility = "visible";
|
||||
} else {
|
||||
imagechk.src = "";
|
||||
imagechk.src = "interfaces/default/images/fail.png";
|
||||
imagechk.style.visibility = "visible";
|
||||
}
|
||||
});
|
||||
$('#ajaxMsg').addClass('success').fadeIn().delay(3000).fadeOut();
|
||||
});
|
||||
|
||||
$(function() {
|
||||
$( "#tabs" ).tabs();
|
||||
});
|
||||
|
|
|
@ -2796,6 +2796,11 @@ class PostProcessor(object):
|
|||
slack = notifiers.SLACK()
|
||||
slack.notify("Download and Postprocessing completed", prline, module=module)
|
||||
|
||||
if mylar.CONFIG.EMAIL_ENABLED and mylar.CONFIG.EMAIL_ONPOST:
|
||||
logger.info(u"Sending email notification")
|
||||
email = notifiers.EMAIL()
|
||||
email.notify(prline2, "Mylar notification - Processed", module=module)
|
||||
|
||||
return
|
||||
|
||||
class FolderCheck():
|
||||
|
|
|
@ -186,6 +186,17 @@ _CONFIG_DEFINITIONS = OrderedDict({
|
|||
'SLACK_WEBHOOK_URL': (str, 'SLACK', None),
|
||||
'SLACK_ONSNATCH': (bool, 'SLACK', False),
|
||||
|
||||
'EMAIL_ENABLED': (bool, 'Email', False),
|
||||
'EMAIL_FROM': (str, 'Email', ''),
|
||||
'EMAIL_TO': (str, 'Email', ''),
|
||||
'EMAIL_SERVER': (str, 'Email', ''),
|
||||
'EMAIL_USER': (str, 'Email', ''),
|
||||
'EMAIL_PASSWORD': (str, 'Email', ''),
|
||||
'EMAIL_PORT': (int, 'Email', 25),
|
||||
'EMAIL_ENC': (int, 'Email', 0),
|
||||
'EMAIL_ONGRAB': (bool, 'Email', True),
|
||||
'EMAIL_ONPOST': (bool, 'Email', True),
|
||||
|
||||
'POST_PROCESSING': (bool, 'PostProcess', False),
|
||||
'FILE_OPTS': (str, 'PostProcess', 'move'),
|
||||
'SNATCHEDTORRENT_NOTIFY': (bool, 'PostProcess', False),
|
||||
|
|
|
@ -27,6 +27,9 @@ import time
|
|||
import simplejson
|
||||
import json
|
||||
import requests
|
||||
import smtplib
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
# This was obviously all taken from headphones with great appreciation :)
|
||||
|
||||
|
@ -479,6 +482,53 @@ class TELEGRAM:
|
|||
def test_notify(self):
|
||||
return self.notify('Test Message: Release the Ninjas!')
|
||||
|
||||
class EMAIL:
|
||||
def __init__(self, test_emailfrom=None, test_emailto=None, test_emailsvr=None, test_emailport=None, test_emailuser=None, test_emailpass=None, test_emailenc=None):
|
||||
self.emailfrom = mylar.CONFIG.EMAIL_FROM if test_emailfrom is None else test_emailfrom
|
||||
self.emailto = mylar.CONFIG.EMAIL_TO if test_emailto is None else test_emailto
|
||||
self.emailsvr = mylar.CONFIG.EMAIL_SERVER if test_emailsvr is None else test_emailsvr
|
||||
self.emailport = mylar.CONFIG.EMAIL_PORT if test_emailport is None else test_emailport
|
||||
self.emailuser = mylar.CONFIG.EMAIL_USER if test_emailuser is None else test_emailuser
|
||||
self.emailpass = mylar.CONFIG.EMAIL_PASSWORD if test_emailpass is None else test_emailpass
|
||||
self.emailenc = mylar.CONFIG.EMAIL_ENC if test_emailenc is None else int(test_emailenc)
|
||||
|
||||
def notify(self, message, subject, module=None):
|
||||
if module is None:
|
||||
module = ''
|
||||
module += '[NOTIFIER]'
|
||||
sent_successfully = False
|
||||
|
||||
try:
|
||||
logger.debug(module + u' Sending email notification. From: [%s] - To: [%s] - Server: [%s] - Port: [%s] - Username: [%s] - Password: [********] - Encryption: [%s] - Message: [%s]' % (self.emailfrom, self.emailto, self.emailsvr, self.emailport, self.emailuser, self.emailenc, message))
|
||||
msg = MIMEMultipart()
|
||||
msg['From'] = str(self.emailfrom)
|
||||
msg['To'] = str(self.emailto)
|
||||
msg['Subject'] = subject
|
||||
msg.attach(MIMEText(message, 'plain'))
|
||||
|
||||
if self.emailenc is 1:
|
||||
sock = smtplib.SMTP_SSL(self.emailsvr, str(self.emailport))
|
||||
else:
|
||||
sock = smtplib.SMTP(self.emailsvr, str(self.emailport))
|
||||
|
||||
if self.emailenc is 2:
|
||||
sock.starttls()
|
||||
|
||||
if self.emailuser or self.emailpass:
|
||||
sock.login(str(self.emailuser), str(self.emailpass))
|
||||
|
||||
sock.sendmail(str(self.emailfrom), str(self.emailto), msg.as_string())
|
||||
sock.quit()
|
||||
sent_successfully = True
|
||||
|
||||
except Exception, e:
|
||||
logger.warn(module + u' Oh no!! Email notification failed: ' + str(e))
|
||||
|
||||
return sent_successfully
|
||||
|
||||
def test_notify(self):
|
||||
return self.notify('Test Message: With great power comes great responsibility.', 'Mylar notification - Test')
|
||||
|
||||
class SLACK:
|
||||
def __init__(self, test_webhook_url=None):
|
||||
self.webhook_url = mylar.CONFIG.SLACK_WEBHOOK_URL if test_webhook_url is None else test_webhook_url
|
||||
|
|
|
@ -2753,6 +2753,10 @@ def notify_snatch(sent_to, comicname, comyear, IssueNumber, nzbprov, pack):
|
|||
logger.info(u"Sending Slack notification")
|
||||
slack = notifiers.SLACK()
|
||||
slack.notify("Snatched", snline, snatched_nzb=snatched_name, sent_to=sent_to, prov=nzbprov)
|
||||
if mylar.CONFIG.EMAIL_ENABLED and mylar.CONFIG.EMAIL_ONGRAB:
|
||||
logger.info(u"Sending email notification")
|
||||
email = notifiers.EMAIL()
|
||||
email.notify(snline + " - " + snatched_name, "Mylar notification - Snatch", module="[SEARCH]")
|
||||
|
||||
return
|
||||
|
||||
|
|
|
@ -5093,6 +5093,18 @@ class WebInterface(object):
|
|||
"slack_enabled": helpers.checked(mylar.CONFIG.SLACK_ENABLED),
|
||||
"slack_webhook_url": mylar.CONFIG.SLACK_WEBHOOK_URL,
|
||||
"slack_onsnatch": helpers.checked(mylar.CONFIG.SLACK_ONSNATCH),
|
||||
"email_enabled": helpers.checked(mylar.CONFIG.EMAIL_ENABLED),
|
||||
"email_from": mylar.CONFIG.EMAIL_FROM,
|
||||
"email_to": mylar.CONFIG.EMAIL_TO,
|
||||
"email_server": mylar.CONFIG.EMAIL_SERVER,
|
||||
"email_user": mylar.CONFIG.EMAIL_USER,
|
||||
"email_password": mylar.CONFIG.EMAIL_PASSWORD,
|
||||
"email_port": int(mylar.CONFIG.EMAIL_PORT),
|
||||
"email_raw": helpers.radio(int(mylar.CONFIG.EMAIL_ENC), 0),
|
||||
"email_ssl": helpers.radio(int(mylar.CONFIG.EMAIL_ENC), 1),
|
||||
"email_tls": helpers.radio(int(mylar.CONFIG.EMAIL_ENC), 2),
|
||||
"email_ongrab": helpers.checked(mylar.CONFIG.EMAIL_ONGRAB),
|
||||
"email_onpost": helpers.checked(mylar.CONFIG.EMAIL_ONPOST),
|
||||
"enable_extra_scripts": helpers.checked(mylar.CONFIG.ENABLE_EXTRA_SCRIPTS),
|
||||
"extra_scripts": mylar.CONFIG.EXTRA_SCRIPTS,
|
||||
"enable_snatch_script": helpers.checked(mylar.CONFIG.ENABLE_SNATCH_SCRIPT),
|
||||
|
@ -5363,7 +5375,7 @@ class WebInterface(object):
|
|||
'lowercase_filenames', 'autowant_upcoming', 'autowant_all', 'comic_cover_local', 'alternate_latest_series_covers', 'cvinfo', 'snatchedtorrent_notify',
|
||||
'prowl_enabled', 'prowl_onsnatch', 'nma_enabled', 'nma_onsnatch', 'pushover_enabled', 'pushover_onsnatch', 'boxcar_enabled',
|
||||
'boxcar_onsnatch', 'pushbullet_enabled', 'pushbullet_onsnatch', 'telegram_enabled', 'telegram_onsnatch', 'slack_enabled', 'slack_onsnatch',
|
||||
'opds_enable', 'opds_authentication', 'opds_metainfo', 'enable_ddl']
|
||||
'email_enabled', 'email_enc', 'email_ongrab', 'email_onpost', 'opds_enable', 'opds_authentication', 'opds_metainfo', 'enable_ddl']
|
||||
|
||||
for checked_config in checked_configs:
|
||||
if checked_config not in kwargs:
|
||||
|
@ -5922,6 +5934,16 @@ class WebInterface(object):
|
|||
return "Error sending test message to Slack"
|
||||
testslack.exposed = True
|
||||
|
||||
def testemail(self, emailfrom, emailto, emailsvr, emailport, emailuser, emailpass, emailenc):
|
||||
email = notifiers.EMAIL(test_emailfrom=emailfrom, test_emailto=emailto, test_emailsvr=emailsvr, test_emailport=emailport, test_emailuser=emailuser, test_emailpass=emailpass, test_emailenc=emailenc)
|
||||
result = email.test_notify()
|
||||
|
||||
if result == True:
|
||||
return "Successfully sent email. Check your mailbox."
|
||||
else:
|
||||
logger.warn('Email test has gone horribly wrong. Variables used were [FROM: %s] [TO: %s] [SERVER: %s] [PORT: %s] [USER: %s] [PASSWORD: ********] [ENCRYPTION: %s]' % (emailfrom, emailto, emailsvr, emailport, emailuser, emailenc))
|
||||
return "Error sending test message via email"
|
||||
testemail.exposed = True
|
||||
|
||||
def testrtorrent(self, host, username, password, auth, verify, rpc_url):
|
||||
import torrent.clients.rtorrent as TorClient
|
||||
|
|
Loading…
Reference in New Issue