From dceb7d832aa698697d466984e5543b20a2458e7c Mon Sep 17 00:00:00 2001 From: akanealw Date: Sat, 26 Aug 2023 13:16:15 -0500 Subject: [PATCH] added email config --- .../proxmox/proxmox-pbs-essentials.sh | 30 +++++++++++++++++++ .../proxmox/proxmox-pve-essentials.sh | 30 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/files/bashscripts/proxmox/proxmox-pbs-essentials.sh b/files/bashscripts/proxmox/proxmox-pbs-essentials.sh index 0d813d3..6618006 100755 --- a/files/bashscripts/proxmox/proxmox-pbs-essentials.sh +++ b/files/bashscripts/proxmox/proxmox-pbs-essentials.sh @@ -65,3 +65,33 @@ git config --global credential.helper store git config --global user.name "akanealw" git config --global user.email "akanealw@gmail.com" git config --global init.defaultBranch main + +# configure email for sending notifications +isInFile=$(cat /etc/postfix/main.cf | grep -c "gmail") +if [ $isInFile -eq 0 ] + then + DEBIAN_FRONTEND=noninteractive apt install -y libsasl2-modules mailutils postfix postfix-pcre + echo "smtp.gmail.com notify.akanealw@gmail.com:leawkqqpthbwacrf" > /etc/postfix/sasl_passwd + echo "/^From:.*/ REPLACE From: $(hostname) " > /etc/postfix/smtp_header_checks + chmod 600 /etc/postfix/sasl_passwd + postmap hash:/etc/postfix/sasl_passwd + postmap hash:/etc/postfix/smtp_header_checks + sed -i 's@relayhost =@#relayhost = @g' /etc/postfix/main.cf + sed -i 's@smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache@#smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache@g' /etc/postfix/main.cf + echo "" >> /etc/postfix/main.cf + echo "# google mail configuration" >> /etc/postfix/main.cf + echo "relayhost = smtp.gmail.com:587" >> /etc/postfix/main.cf + echo "smtp_use_tls = yes" >> /etc/postfix/main.cf + echo "smtp_sasl_auth_enable = yes" >> /etc/postfix/main.cf + echo "smtp_sasl_security_options =" >> /etc/postfix/main.cf + echo "smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd" >> /etc/postfix/main.cf + echo "smtp_tls_CAfile = /etc/ssl/certs/Entrust_Root_Certification_Authority.pem" >> /etc/postfix/main.cf + echo "smtp_tls_session_cache_database = btree:/var/lib/postfix/smtp_tls_session_cache" >> /etc/postfix/main.cf + echo "smtp_tls_session_cache_timeout = 3600s" >> /etc/postfix/main.cf + echo "smtp_header_checks = pcre:/etc/postfix/smtp_header_checks" >> /etc/postfix/main.cf + echo "" >> /etc/postfix/main.cf + postfix reload + echo "This is a test message sent from postfix on $(hostname)" | mail -s "Test Email from $(hostname)" akanealw@gmail.com + else + echo "Email already configured." +fi diff --git a/files/bashscripts/proxmox/proxmox-pve-essentials.sh b/files/bashscripts/proxmox/proxmox-pve-essentials.sh index e15f18f..778e2fc 100644 --- a/files/bashscripts/proxmox/proxmox-pve-essentials.sh +++ b/files/bashscripts/proxmox/proxmox-pve-essentials.sh @@ -71,3 +71,33 @@ git config --global credential.helper store git config --global user.name "akanealw" git config --global user.email "akanealw@gmail.com" git config --global init.defaultBranch main + +# configure email for sending notifications +isInFile=$(cat /etc/postfix/main.cf | grep -c "gmail") +if [ $isInFile -eq 0 ] + then + DEBIAN_FRONTEND=noninteractive apt install -y libsasl2-modules mailutils postfix postfix-pcre + echo "smtp.gmail.com notify.akanealw@gmail.com:leawkqqpthbwacrf" > /etc/postfix/sasl_passwd + echo "/^From:.*/ REPLACE From: $(hostname) " > /etc/postfix/smtp_header_checks + chmod 600 /etc/postfix/sasl_passwd + postmap hash:/etc/postfix/sasl_passwd + postmap hash:/etc/postfix/smtp_header_checks + sed -i 's@relayhost =@#relayhost = @g' /etc/postfix/main.cf + sed -i 's@smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache@#smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache@g' /etc/postfix/main.cf + echo "" >> /etc/postfix/main.cf + echo "# google mail configuration" >> /etc/postfix/main.cf + echo "relayhost = smtp.gmail.com:587" >> /etc/postfix/main.cf + echo "smtp_use_tls = yes" >> /etc/postfix/main.cf + echo "smtp_sasl_auth_enable = yes" >> /etc/postfix/main.cf + echo "smtp_sasl_security_options =" >> /etc/postfix/main.cf + echo "smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd" >> /etc/postfix/main.cf + echo "smtp_tls_CAfile = /etc/ssl/certs/Entrust_Root_Certification_Authority.pem" >> /etc/postfix/main.cf + echo "smtp_tls_session_cache_database = btree:/var/lib/postfix/smtp_tls_session_cache" >> /etc/postfix/main.cf + echo "smtp_tls_session_cache_timeout = 3600s" >> /etc/postfix/main.cf + echo "smtp_header_checks = pcre:/etc/postfix/smtp_header_checks" >> /etc/postfix/main.cf + echo "" >> /etc/postfix/main.cf + postfix reload + echo "This is a test message sent from postfix on $(hostname)" | mail -s "Test Email from $(hostname)" akanealw@gmail.com + else + echo "Email already configured." +fi