diff --git a/tester.py b/tester.py
index 50db9491fc8fae21b277b4f9c2798128191ae8bb..fc014f28d9840666b9c1515d1d8d261baf4efb20 100755
--- a/tester.py
+++ b/tester.py
@@ -35,11 +35,13 @@ sys.stderr = sys.stdout
 
 
 class Tester():
-    USAGE = '''%s [-e] [-b] [-d] [-h]
+    USAGE = '''%s [-e] [-f] [-b] [-d] [-h]
     -e: send email with report.
+    -f: send email with report only if at least one test failed.
     -b: run only basic tests (exclude mediaserver tests).
     -d: debug mode (can be started with non root users).
     -h: show this message.''' % __file__
+    VALID_ARGS = ['-e', '-f', '-b', '-d', '-h']
 
     def __init__(self, *args):
         log('\033[96m-------------------------------\033[0m')
@@ -50,6 +52,11 @@ class Tester():
         if '-h' in args:
             log('USAGE: ' + self.USAGE)
             sys.exit(0)
+        for arg in args:
+            if arg not in self.VALID_ARGS:
+                log('Invalid argument given: "%s".\n' % arg)
+                log('USAGE: ' + self.USAGE)
+                sys.exit(1)
         # Check current dir
         root_dir = utils.get_dir(__file__)
         if root_dir != '':
@@ -71,11 +78,12 @@ class Tester():
             sys.exit(1)
         # Check for email value
         email = '-e' in args
+        email_if_fail = '-f' in args
         basic_only = '-b' in args
         tests = self.discover_tests(basic_only)
         if not tests:
             sys.exit(1)
-        exit_code = self.run_tests(tests, email)
+        exit_code = self.run_tests(tests, email, email_if_fail)
         sys.exit(exit_code)
 
     def get_file_description(self, path):
@@ -150,7 +158,7 @@ class Tester():
                     tests.append(('%s (%s)' % (name, user), description, [test_path, user]))
         return tests
 
-    def run_tests(self, tests, email=False):
+    def run_tests(self, tests, email=False, email_if_fail=False):
         results = list()
         exit_code = 0
         # Run all tests
@@ -194,7 +202,7 @@ class Tester():
             html_report += '\n<tr><td>%s</td><td>%s</td><td>%s</td></tr>' % (name, html_result, description.replace('\n', '<br/>\n'))
         html_report += '\n</table>'
         # Send email
-        if email:
+        if email or email_if_fail and exit_code != 0:
             log('')
             hostname = subprocess.check_output(['hostname'])
             if not hostname: