diff --git a/tests/test_email.py b/tests/test_email.py
index 433efc537c09dc6588fe3b38aaa4f5b8342bbc78..81ecc1147a3cc8511633a06f9c856b5293014283 100755
--- a/tests/test_email.py
+++ b/tests/test_email.py
@@ -60,7 +60,7 @@ def check_relay(relay_host: str, relay_port: str, domain: str) -> tuple:
     errors = 0
 
     # get relayhost value from Postfix config
-    status, out = subprocess.getstatusoutput("grep relayhost /etc/postfix/main.cf")
+    status, out = subprocess.getstatusoutput("grep -E '^relayhost' /etc/postfix/main.cf")
 
     if status == 0:
         configured_relay = (
@@ -75,7 +75,7 @@ def check_relay(relay_host: str, relay_port: str, domain: str) -> tuple:
             with open("/etc/mailname", "r") as mailname:
                 myorigin = mailname.read().strip()
         else:
-            out = subprocess.getoutput("grep myorigin /etc/postfix/main.cf")
+            out = subprocess.getoutput("grep -E '^myorigin' /etc/postfix/main.cf")
             myorigin = out.replace("myorigin", "").strip()
         # possible origin names
         origins = set(