Advertisement
iWrench

sendmail via curl

Jul 15th, 2020
2,256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.33 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. function getinfo
  4. {
  5.         echo "" >> /tmp/mail.txt
  6.         echo "Technical INFO:" >> /tmp/mail.txt
  7.         echo "" >> /tmp/mail.txt
  8.         hostname --ip >> /tmp/mail.txt
  9.         free  >> /tmp/mail.txt
  10.         df -h  >> /tmp/mail.txt
  11.         echo "" >> /tmp/mail.txt
  12.         echo "Asterisk STATUS: " >> /tmp/mail.txt
  13.         service asterisk status  >> /tmp/mail.txt
  14.         echo "" >> /tmp/mail.txt
  15.         echo "Centos8 STATUS: " >> /tmp/mail.txt
  16.         systemctl status cockpit.socket >>  /tmp/mail.txt
  17.         echo "" >>  /tmp/mail.txt
  18.         echo "Registration's STATUS:" >>  /tmp/mail.txt
  19.         asterisk -rx "sip show peers" | grep -v Unspecified >>  /tmp/mail.txt
  20. }
  21.  
  22. dt=`date`
  23. host=($(hostname --ip | tr " " "\n"))
  24.  
  25. if [ -n "$1" ]
  26. then
  27.         echo "From: root@$host <automailer@asterisk.com>" > /tmp/mail.txt
  28.         echo "To: Customer <$1>" >> /tmp/mail.txt
  29.         echo "Subject: Новое событие на SIP сервере TrueIP $host" >> /tmp/mail.txt
  30.         echo "Date: $dt" >> /tmp/mail.txt
  31. else
  32.         echo ""
  33.         echo "Using: ./sendmail TO MESSAGE [file to attach] [TECHINFO]"
  34.         echo "Powered by iMiro Wrench. Saint-Petersburg, Russia, July 2020"
  35.         echo ""
  36.         exit 0
  37. fi
  38.  
  39. if [ -n "$2" ]
  40. then
  41.         echo "" >> /tmp/mail.txt
  42.         echo $2 >> /tmp/mail.txt
  43. else
  44.         echo "" >> /tmp/mail.txt
  45.         echo "Something happens now on your SIP server." >> /tmp/mail.txt
  46.         getinfo
  47. fi
  48. if [ -n "$3" ]
  49. then
  50.         FILE=$1
  51.         if [ -f "$FILE" ]; then
  52.                 echo "" >> /tmp/mail.txt
  53.                 echo "--------------------Attached file:--------------------" >> /tmp/mail.txt
  54.                 echo "" >> /tmp/mail.txt
  55.                 cat $3 >> /tmp/mail.txt
  56.                 echo "" >> /tmp/mail.txt
  57.                 echo "-----------------End of attached file:----------------" >> /tmp/mail.txt
  58.         else
  59.                 getinfo
  60.         fi
  61. fi
  62.         echo "" >> /tmp/mail.txt
  63.         echo "Best regards, TrueIP Team. Saint-Petersburg, Russia. 2020" >> /tmp/mail.txt
  64. if [ -n "$4" ]
  65. then
  66.         getinfo
  67. fi
  68. curl --ssl-reqd \
  69.         --url 'smtps://smtp.gmail.com:465' \
  70.         --user 'timianalias@gmail.com:aa483861' \
  71.         --mail-from 'automailer@asterisk.com' \
  72.         --mail-rcpt `echo $1` \
  73.         --upload-file /tmp/mail.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement