email.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/sh
  2. echo '
  3. __ __ _ _
  4. | \/ |__ _(_) |
  5. | |\/| / _` | | |
  6. |_| |_\__,_|_|_|
  7. '
  8. echo "Enable mail sending for php"
  9. . bin/checkroot.sh
  10. # get the current position
  11. _cwd="$(pwd)"
  12. # check for assets forlder
  13. _assets="$_cwd/assets"
  14. if [ ! -d "$_assets" ]; then
  15. _assets="$_cwd/../assets"
  16. if [ ! -d "$_assets" ]; then
  17. echo "!! can't find assets directory !!"
  18. exit
  19. fi
  20. fi
  21. sleep 2
  22. apk add postfix mailx
  23. mkdir /var/mail
  24. postmap /etc/postfix/aliases
  25. rc-update add postfix
  26. /etc/init.d/postfix start
  27. # https://www.cyberciti.biz/faq/how-to-find-out-the-ip-address-assigned-to-eth0-and-display-ip-only/
  28. _IP=$(ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
  29. _MASK=$(ifconfig eth0 | grep 'inet addr:' | cut -d: -f4)
  30. # TODO: change bounce email
  31. # echo -n "Please provide a bounce email address: "
  32. # read _bounce_email
  33. # TODO: DMARC
  34. # reverse dns
  35. # dkim
  36. echo "Configuring DKIM"
  37. apk add opendkim opendkim-utils
  38. mkdir /etc/opendkim/keys
  39. opendkim-genkey -b 2048 -d "$HOSTNAME" -s "$HOSTNAME".dkim --directory=/etc/opendkim/keys/
  40. chown opendkim:opendkim /etc/opendkim/keys/*
  41. mv /etc/opendkim/opendkim.conf /etc/opendkim/opendkim.conf.back
  42. cp "$_assets"/opendkim/opendkim.conf /etc/opendkim/opendkim.conf
  43. echo "*@$HOSTNAME $HOSTNAME" > /etc/opendkim/signtable
  44. echo "$HOSTNAME $HOSTNAME:mail:/etc/opendkim/keys/$HOSTNAME.dkim.private" > /etc/opendkim/keytable
  45. echo -e "localhost\n127.0.0.1\n$HOSTNAME\n$_IP/$_MASK" > /etc/internalhosts
  46. echo -e "smtpd_milters = unix:/run/opendkim/opendkim.sock\nnon_smtpd_milters = unix:/run/opendkim/opendkim.sock" >> /etc/postfix/main.cf
  47. rc-update add opendkim
  48. service opendkim start
  49. usermod -a -G opendkim postfix
  50. service postfix restart
  51. echo -e "DKIM"
  52. echo -e "please create a DKIM entry in your dns zone : mail._domainkey.$HOSTNAME \n"
  53. echo -e "your public key is : \n"
  54. cat /etc/opendkim/keys/"$HOSTNAME".dkim.txt
  55. echo -e "SPF"
  56. echo -e "you should edit an spf entry for $HOSTNAME in your dns zone :"
  57. echo -e "v=spf1 a mx ip4:$_IP"
  58. echo -e "MX"
  59. echo -e "If it does not exists, you should create an mx zone record for $HOSTNAME"
  60. echo "press any key to continue."
  61. read continu