$T('emailAccount')
@@ -139,10 +139,12 @@
\$('#email_dir').fileBrowser({ title: 'Select $T('opt-email_dir')' });
\$('#test_email').click(function () {
if (confirm(\$('#test_email').attr('rel'))) {
+ var data = { mode: 'test_email', apikey: '$session', output: 'json' };
+ \$("#email").extractFormDataTo(data);
\$.ajax({
type: "GET",
url: "../../tapi",
- data: {mode: 'test_email', apikey: '$session', output: 'json' },
+ data: data,
beforeSend: function () {
\$('#test_email').attr("disabled", "disabled");
\$('#testmail-result').removeClass("success failure").addClass("loading").html('$T('post-Verifying')');
diff --git a/sabnzbd/api.py b/sabnzbd/api.py
index 1fc4ef2..f26009c 100644
--- a/sabnzbd/api.py
+++ b/sabnzbd/api.py
@@ -682,7 +682,8 @@ def _api_test_email(name, output, kwargs):
pack['unpack'] = ['action 1', 'action 2']
res = sabnzbd.emailer.endjob('I had a d\xe8ja vu', 123, 'unknown', True,
os.path.normpath(os.path.join(cfg.complete_dir.get_path(), '/unknown/I had a d\xe8ja vu')),
- 123*MEBI, None, pack, 'my_script', 'Line 1\nLine 2\nLine 3\nd\xe8ja vu\n', 0)
+ 123*MEBI, None, pack, 'my_script', 'Line 1\nLine 2\nLine 3\nd\xe8ja vu\n', 0,
+ test=kwargs)
if res == 'Email succeeded':
res = None
return report(output, error=res)
diff --git a/sabnzbd/emailer.py b/sabnzbd/emailer.py
index c70fc71..2794922 100644
--- a/sabnzbd/emailer.py
+++ b/sabnzbd/emailer.py
@@ -37,22 +37,40 @@ def errormsg(msg):
logging.error(latin1(msg))
return msg
+
+
################################################################################
# EMAIL_SEND
#
#
################################################################################
-def send(message, recipient):
+def send(message, email_to, test=None):
""" Send message if message non-empty and email-parms are set """
+ # we should not use CFG if we are testing. we should use values
+ # from UI instead.
+
+ if test:
+ email_server = test.get('email_server')
+ email_from = test.get('email_from')
+ email_account = test.get('email_account')
+ email_pwd = test.get('email_pwd')
+ else:
+ email_server = cfg.email_server()
+ email_from = cfg.email_from()
+ email_account = cfg.email_account()
+ email_pwd = cfg.email_pwd()
+
+ # email_to is replaced at send_with_template, since it can be an array
+
if not message.strip('\n\r\t '):
return "Skipped empty message"
- if cfg.email_server() and recipient and cfg.email_from():
+ if email_server and email_to and email_from:
message = _prepare_message(message)
- server, port = split_host(cfg.email_server())
+ server, port = split_host(email_server)
if not port:
port = 25
@@ -92,14 +110,14 @@ def send(message, recipient):
return errormsg(T('Failed to initiate TLS connection'))
# Authentication
- if (cfg.email_account() != "") and (cfg.email_pwd() != ""):
+ if (email_account != "") and (email_pwd != ""):
try:
- mailconn.login(cfg.email_account(), cfg.email_pwd())
+ mailconn.login(email_account, email_pwd)
except:
return errormsg(T('Failed to authenticate to mail server'))
try:
- mailconn.sendmail(cfg.email_from(), recipient, message)
+ mailconn.sendmail(email_from, email_to, message)
msg = None
except smtplib.SMTPHeloError:
msg = errormsg('The server didn\'t reply properly to the helo greeting.')
@@ -139,7 +157,7 @@ def get_email_date():
################################################################################
from Cheetah.Template import Template
-def send_with_template(prefix, parm):
+def send_with_template(prefix, parm, test=None):
""" Send an email using template """
parm['from'] = cfg.email_from()
@@ -166,15 +184,20 @@ def send_with_template(prefix, parm):
source = _decode_file(temp)
if source:
sent = True
- if len(cfg.email_to()):
- for recipient in cfg.email_to():
+ if test:
+ recipients = [ test.get('email_to') ]
+ else:
+ recipients = cfg.email_to()
+
+ if len(recipients):
+ for recipient in recipients:
parm['to'] = recipient
message = Template(source=source,
searchList=[parm],
filter=EmailFilter,
compilerSettings={'directiveStartToken': ''})
- ret = send(message.respond(), recipient)
+ ret = send(message.respond(), recipient, test)
del message
else:
ret = T('No recipients given, no email sent')
@@ -187,7 +210,7 @@ def send_with_template(prefix, parm):
return ret
-def endjob(filename, msgid, cat, status, path, bytes, fail_msg, stages, script, script_output, script_ret):
+def endjob(filename, msgid, cat, status, path, bytes, fail_msg, stages, script, script_output, script_ret, test=None):
""" Send end-of-job email """
# Translate the stage names
@@ -219,7 +242,7 @@ def endjob(filename, msgid, cat, status, path, bytes, fail_msg, stages, script,
parm['size'] = "%sB" % to_units(bytes)
parm['end_time'] = time.strftime(time_format('%Y-%m-%d %H:%M:%S'), time.localtime(time.time()))
- return send_with_template('email', parm)
+ return send_with_template('email', parm, test)
def rss_mail(feed, jobs):