Small sh "framework" to test some server responses
sh
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mail.sh 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #Copyright (C) 2016,2023 Weber Yann
  2. #
  3. #This program is free software; you can redistribute it and/or modify
  4. #it under the terms of the GNU General Public License as published by
  5. #the Free Software Foundation; either version 3 of the License, or
  6. #any later version.
  7. #
  8. #This program is distributed in the hope that it will be useful,
  9. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. #GNU General Public License for more details.
  12. #
  13. #You should have received a copy of the GNU General Public License
  14. #along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. check_smtp() {
  16. hostname=$1
  17. port=$2
  18. if [ -z "$port" ]
  19. then
  20. port=587
  21. fi
  22. code=$(nc -q0 "$hostname" "$port" < /dev/null | cut -d " " -f1)
  23. if [ "$code" = "220" ]
  24. then
  25. success "SMTP@$hostname server replied 220 status"
  26. else
  27. fail "Unexpected reply from smtp@$hostname '$code'"
  28. fi
  29. }
  30. check_smtp_id() {
  31. hostname=$1
  32. idstr=$2
  33. port=$3
  34. if [ -z "$port" ]
  35. then
  36. port=587
  37. fi
  38. rep=$(nc -q0 "$hostname" "$port" < /dev/null)
  39. if echo "$rep" | grep -e "^220 $idstr" > /dev/null
  40. then
  41. success "SMTP@$hostname server replie '$idstr'"
  42. else
  43. fail "Unexpected reply from smtp@$hostname '$rep'"
  44. fi
  45. }
  46. check_imaps() {
  47. hostname=$1
  48. port=$2
  49. if [ -z "$port" ]
  50. then
  51. port=993
  52. fi
  53. rep=$(echo "01 LOGOUT" | openssl s_client -quiet -verify_quiet -connect "${hostname}:$port" -servername "$hostname")
  54. if echo "$rep" | grep "^01 OK" > /dev/null
  55. then
  56. success "IMAPS@$hostname '$(echo "$rep" | grep "^01 OK")'"
  57. else
  58. fail "Unexpected reply from imaps@$hostname '$rep'"
  59. fi
  60. }