Advertisement
Guest User

Untitled

a guest
Aug 9th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. HOST=$(hostname)
  4.  
  5. function install_postfix() {
  6. echo | sudo debconf-set-selections <<__EOF
  7. postfix postfix/root_address string
  8. postfix postfix/rfc1035_violation boolean false
  9. postfix postfix/mydomain_warning boolean
  10. postfix postfix/mynetworks string 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
  11. postfix postfix/mailname string $HOST
  12. postfix postfix/tlsmgr_upgrade_warning boolean
  13. postfix postfix/recipient_delim string +
  14. postfix postfix/main_mailer_type select Internet with smarthost
  15. postfix postfix/destinations string $HOST, localhost.localdomain, localhost
  16. postfix postfix/retry_upgrade_warning boolean
  17. # Install postfix despite an unsupported kernel?
  18. postfix postfix/kernel_version_warning boolean
  19. postfix postfix/not_configured error
  20. postfix postfix/sqlite_warning boolean
  21. postfix postfix/mailbox_limit string 0
  22. postfix postfix/relayhost string [smtp.gmail.com]:587
  23. postfix postfix/procmail boolean false
  24. postfix postfix/bad_recipient_delimiter error
  25. postfix postfix/protocols select all
  26. postfix postfix/chattr boolean false
  27. __EOF
  28.  
  29. echo "Postfix should be configured as Internet site with smarthost"
  30. sudo apt-get install -q -y postfix
  31. }
  32.  
  33. if ! dpkg -s postfix >/dev/null;
  34. then
  35. install_postfix
  36. else
  37. echo "Postfix is already installed."
  38. echo "You may consider removing it before running the script."
  39. echo "You may do so with the following command:"
  40. echo "sudo apt-get purge postfix"
  41. echo
  42. fi
  43.  
  44. read -p "Gmail username: " GMAIL_USER
  45. read -sp "Gmail password: " GMAIL_PASS
  46.  
  47. echo # an empty line
  48.  
  49. if [ -z "$GMAIL_USER" ]; then echo "No gmail username given. Exiting."; exit -1; fi
  50. if [ -z "$GMAIL_PASS" ]; then echo "No gmail password given. Exiting."; exit -1; fi
  51.  
  52. if ! [ -f /etc/postfix/main.cf.original ]; then
  53. sudo cp /etc/postfix/main.cf /etc/postfix/main.cf.original
  54. fi
  55.  
  56. sudo tee /etc/postfix/main.cf >/dev/null <<__EOF
  57. relayhost = [smtp.gmail.com]:587
  58. smtp_use_tls = yes
  59. smtp_sasl_auth_enable = yes
  60. smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
  61. smtp_sasl_security_options = noanonymous
  62. smtp_tls_loglevel = 1
  63. smtp_tls_per_site = hash:/etc/postfix/tls_per_site
  64. smtp_tls_CAfile = /etc/ssl/certs/Equifax_Secure_CA.pem
  65. smtp_tls_session_cache_database = btree:/var/lib/postfix/smtp_tls_session_cache
  66. __EOF
  67.  
  68. echo "[smtp.gmail.com]:587 $GMAIL_USER:$GMAIL_PASS" | sudo tee /etc/postfix/sasl_passwd >/dev/null
  69. sudo chmod 400 /etc/postfix/sasl_passwd
  70. sudo postmap /etc/postfix/sasl_passwd
  71. echo "smtp.gmail.com MUST" | sudo tee /etc/postfix/tls_per_site >/dev/null
  72. sudo chmod 400 /etc/postfix/tls_per_site
  73. sudo postmap /etc/postfix/tls_per_site
  74.  
  75. sudo service postfix restart
  76. echo "Configuration done"
  77.  
  78. mail -s "Email relaying configured at ${HOST}" $GMAIL_USER@gmail.com <<__EOF
  79. The postfix service has been configured at host '${HOST}'.
  80. Thank you for using this postfix configuration script.
  81. __EOF
  82.  
  83. echo "I have sent you a mail to $GMAIL_USER@gmail.com"
  84. echo "This will confirm that the configuration is good."
  85. echo "Please check your inbox at gmail."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement