email.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/sh
  2. echo '\033[35m
  3. __ ______ ______
  4. / |/ / | / _/ /
  5. / /|_/ / /| | / // /
  6. / / / / ___ |_/ // /___
  7. /_/ /_/_/ |_/___/_____/
  8. \033[0m'
  9. echo "\033[35;1mEnable mail sending for php \033[0m"
  10. if [ "$EUID" -ne 0 ]; then
  11. echo "Please run as root"
  12. exit
  13. fi
  14. # get the current position
  15. _cwd="$(pwd)"
  16. # check for assets forlder
  17. _assets="$_cwd/assets"
  18. if [ ! -d "$_assets" ]; then
  19. _assets="$_cwd/../assets"
  20. if [ ! -d "$_assets" ]; then
  21. echo "!! can't find assets directory !!"
  22. exit
  23. fi
  24. fi
  25. # http://www.sycha.com/lamp-setup-debian-linux-apache-mysql-php#anchor13
  26. sleep 2
  27. apt-get --yes --force-yes install exim4
  28. echo "\033[35;1mConfiguring EXIM4 \033[0m"
  29. while [ "$configexim" != "y" ] && [ "$configexim" != "n" ]
  30. do
  31. echo -n "Should we configure exim4 ? [y|n] "
  32. read configexim
  33. done
  34. if [ "$configexim" = "y" ]; then
  35. echo "choose the first option :internet site; mail is sent and received directly using SMTP. Leave the other options as default exepted for domain name which should be valid domain name if you want your mails to not be considered as spam"
  36. echo "press any key to continue."
  37. read continu
  38. dpkg-reconfigure exim4-config
  39. else
  40. echo 'exim not configured'
  41. fi
  42. systemctl enable exim4
  43. systemctl restart exim4
  44. # dkim spf
  45. # https://debian-administration.org/article/718/DKIM-signing_outgoing_mail_with_exim4
  46. echo "\033[35;1mConfiguring DKIM \033[0m"
  47. while [ "$installdkim" != "y" ] && [ "$installdkim" != "n" ]
  48. do
  49. echo -n "Should we install dkim for exim4 ? [y|n] "
  50. read installdkim
  51. done
  52. if [ "$installdkim" = "y" ]; then
  53. echo -n "Choose a domain for dkim (same domain as you chose before for exim4): "
  54. read domain
  55. selector=$(date +%Y%m%d)
  56. mkdir /etc/exim4/dkim
  57. openssl genrsa -out /etc/exim4/dkim/"$domain"-private.pem 1024 -outform PEM
  58. openssl rsa -in /etc/exim4/dkim/"$domain"-private.pem -out /etc/exim4/dkim/"$domain".pem -pubout -outform PEM
  59. chown root:Debian-exim /etc/exim4/dkim/"$domain"-private.pem
  60. chmod 440 /etc/exim4/dkim/"$domain"-private.pem
  61. cp "$_assets"/exim4_dkim.conf /etc/exim4/conf.d/main/00_local_macros
  62. sed -i -r "s/DOMAIN_TO_CHANGE/$domain/g" /etc/exim4/conf.d/main/00_local_macros
  63. sed -i -r "s/DATE_TO_CHANGE/$selector/g" /etc/exim4/conf.d/main/00_local_macros
  64. update-exim4.conf
  65. systemctl restart exim4
  66. echo "please create a TXT entry in your dns zone : $selector._domainkey.$domain \n"
  67. echo "your public key is : \n"
  68. cat /etc/exim4/dkim/"$domain".pem
  69. echo "press any key to continue."
  70. read continu
  71. else
  72. echo 'dkim not installed'
  73. fi