mludvig / smtp-cli

The ultimate command line SMTP client
http://smtp-cli.logix.cz
188 stars 32 forks source link

print instead of warn #20

Closed omexlu closed 3 years ago

omexlu commented 3 years ago

Hello,

To allow comparisons within a bash script you should replace WARN with PRINT otherwise no comparisons are possible within a bash script.

In any case, I have now manually changed this for me.

mludvig commented 3 years ago

Have you got an example of what doesn't work for you? If the issue is with WARN writing to STDERR you can always redirect that to STDOUT if you like. Check out this about STDERR/STDOUT if it helps.

omexlu commented 3 years ago

I had trouble creating a comparison in a bash-script.

Example:

CHECK_DOMAIN_RELAY_25=$(/home/USER/smtp-cli --hello-host keeper-us-east-1c.mxtoolbox.com --host domain.tld:25 --from supertool@mxtoolboxsmtpdiag.com --to test@mxtoolboxsmtpdiag.com --data 'TEST OPEN-REPLAY (PORT: 25)' | tr -d '\r')

SEARCH_RELAY="554 5.7.1"

if [[ $CHECK_DOMAIN_RELAY_25 =~ $SEARCH_RELAY ]]; then
    echo "NO OPEN-RELAY (PORT: 25)"
else
    echo "OPEN-RELAY (PORT: 25)"
fi

After I changed warn to print in smtp-cli the comparison worked, with warn no correct comparison could be created.

After I changed that it worked, but I don't know how to do it differently.

Thanks in advance.

mludvig commented 3 years ago

The right way to do this is redirecting STDERR to STDOUT and then assign that to the variable:

CHECK_DOMAIN_RELAY_25=$(/home/USER/smtp-cli --hello-host ... --data '...' 2>&1 | tr -d '\r')

Note the 2>&1 that redirects STDERR (error output) to STDOUT (standard non-error output).

There's a reason why we use warn() and not print() - warn is obviously for errors. I suggest you read up on stderr, see my previous link above.

omexlu commented 3 years ago

Thank you for your answer, I will see if I undo the changes.

But there is no problem, even if I have now replaced warn() with print() and leave it on print()?

mludvig commented 3 years ago

If it works for your purpose with print() go ahead and do it. It's just that I won't be making the change in my repo.

Thanks for using smtp-cli by the way :)

omexlu commented 3 years ago

Yes, it works because I believe that print() streams to STDOUT.

Is this the correct way to check the other ports for open-relay?:

CHECK_DOMAIN_RELAY_465=$(/home/USER/smtp-cli --ssl --hello-host keeper-us-east-1c.mxtoolbox.com --host domain.tld:465 --from supertool@mxtoolboxsmtpdiag.com --to test@mxtoolboxsmtpdiag.com --data 'TEST OPEN-REPLAY (PORT: 465)' | tr -d '\r')

CHECK_DOMAIN_RELAY_587=$(/home/USER/smtp-cli --hello-host keeper-us-east-1c.mxtoolbox.com --host domain.tld:587 --from supertool@mxtoolboxsmtpdiag.com --to test@mxtoolboxsmtpdiag.com --data 'TEST OPEN-REPLAY (PORT: 587)' | tr -d '\r')

SEARCH_RELAY="554 5.7.1"

if [[ $CHECK_DOMAIN_RELAY_465 =~ $SEARCH_RELAY ]]; then
    echo "NO OPEN-RELAY (PORT: 465)"
else
    echo "OPEN-RELAY (PORT: 465)"
fi

if [[ $CHECK_DOMAIN_RELAY_587 =~ $SEARCH_RELAY ]]; then
    echo "NO OPEN-RELAY (PORT: 587)"
else
    echo "OPEN-RELAY (PORT: 587)"
fi

Maybe you have any suggestion on testing this other 2 ports :)

omexlu commented 3 years ago

Hi @mludvig,

Did you take a look at it above? :)