Page 1 of 1

Conditional Email - No Subject

Posted: June 20th, 2010, 2:34 pm
by kentbrockman
I'm trying to set up a conditional email notification template so that I only receive emails when files of "tv" category are downloaded.

Here is my custom template:

Code: Select all

##
## Default Email template for SABnzbd
## This a Cheetah template
## Documentation: http://sabnzbd.wikidot.com/email-templates
##
## Newlines and whitespace are significant!
##
## These are the email headers
<!--#if $cat == "tv" #-->
subject: SABnzbd has <!--#if $status then "completed" else "failed" #--> job $name
to: $to
from: $from
date: $date
subject: SABnzbd has <!--#if $status then "completed" else "failed" #--> job $name
X-priority: 5
X-MS-priority: 5
## After this comes the body, the empty line is required!

Hi,
<!--#if $status #-->
SABnzbd has downloaded "$name" <!--#if $msgid=="" then "" else "(newzbin #" + $msgid + ")"#-->
<!--#else#-->
SABnzbd has failed to download "$name" <!--#if $msgid=="" then "" else "(newzbin #" + $msgid + ")"#-->
<!--#end if#-->
Finished at $end_time
Downloaded $size

Results of the job:
<!--#for $stage in $stages #-->
Stage $stage <!--#slurp#-->
<!--#for $result in $stages[$stage]#-->
    $result <!--#slurp#-->
<!--#end for#-->
<!--#end for#-->
<!--#if $script!="" #-->
Output from user script "$script" (Exit code = $script_ret):
$script_output
<!--#end if#-->
<!--#if $status #-->
Enjoy!
<!--#else#-->
Sorry!
<!--#end if#-->
<!--#end if#-->
I have added the if statement at the top as described in the help.
The template does work, except  the resulting email does not have a subject, which is because the "subject:" value comes after the if statement.
But if I pull the if statement up I end up receiving emails for all downloads.

Does anyone have any ideas how to fix this?

Cheers,
Kent

Re: Conditional Email - No Subject

Posted: June 20th, 2010, 3:35 pm
by shypike
The end result contains a empty line at the beginning, this is fatal.
(Sorry, that's the way the email protocol works, but we're going to fix that in 0.5.3).
You can remove this by adding "slurp".

Code: Select all

<!--#if $cat == "tv" #--><!--#slurp#-->
subject: SABnzbd has <!--#if $status then "completed" else "failed" #--> job $name
BTW: You also have a double subject line.

I'll change the Wiki instructions.

Re: Conditional Email - No Subject

Posted: June 20th, 2010, 8:53 pm
by kentbrockman
shypike,

Thanks for the quick response.
Your solution works like a charm.

Cheers,
Kent