diff options
-rwxr-xr-x | emailwiz.sh | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/emailwiz.sh b/emailwiz.sh index 829eeef..96f2bfd 100755 --- a/emailwiz.sh +++ b/emailwiz.sh @@ -17,6 +17,8 @@ echo "Installing programs..." apt install postfix dovecot-imapd opendkim spamassassin spamc +# Install another requirement for opendikm only if the above command didn't get it already +[ -e $(which opendkim-genkey) ] || apt install opendkim-tools domain="$(cat /etc/mailname)" subdom="mail" maildomain="$subdom.$domain" @@ -62,15 +64,14 @@ sed -i "/^\s*-o/d;/^\s*submission/d;/^\s*smtp/d" /etc/postfix/master.cf echo "smtp unix - - n - - smtp smtp inet n - y - - smtpd + -o content_filter=spamassassin submission inet n - y - - smtpd -o syslog_name=postfix/submission -o smtpd_tls_security_level=encrypt - -o content_filter=spamassassin -o smtpd_sasl_auth_enable=yes -o smtpd_tls_auth_only=yes smtps inet n - y - - smtpd -o syslog_name=postfix/smtps - -o content_filter=spamassassin -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes spamassassin unix - n n - - pipe @@ -143,14 +144,40 @@ service auth { group = postfix } } + +protocol lda { + mail_plugins = \$mail_plugins sieve +} + +protocol lmtp { + mail_plugins = \$mail_plugins sieve +} + +plugin { + sieve = ~/.dovecot.sieve + sieve_default = /var/lib/dovecot/sieve/default.sieve + #sieve_global_path = /var/lib/dovecot/sieve/default.sieve + sieve_dir = ~/.sieve + sieve_global_dir = /var/lib/dovecot/sieve/ +} " > /etc/dovecot/dovecot.conf +mkdir /var/lib/dovecot/sieve/ + +echo "require [\"fileinto\", \"mailbox\"]; +if header :contains \"X-Spam-Flag\" \"YES\" + { + fileinto \"Junk\"; + }" > /var/lib/dovecot/sieve/default.sieve + +chown -R vmail:vmail /var/lib/dovecot +sievec /var/lib/dovecot/sieve/default.sieve + echo "Preparing user authetication..." grep nullok /etc/pam.d/dovecot >/dev/null || echo "auth required pam_unix.so nullok account required pam_unix.so" >> /etc/pam.d/dovecot - # OpenDKIM # A lot of the big name email services, like Google, will automatically rejectmark as spam unfamiliar and unauthenticated email addresses. As in, the server will flattly reject the email, not even deliverring it to someone's Spam folder. @@ -193,7 +220,7 @@ postconf -e "milter_default_action = accept" postconf -e "milter_protocol = 2" postconf -e "smtpd_milters = inet:localhost:8891" postconf -e "non_smtpd_milters = inet:localhost:8891" - +postconf -e "mailbox_command = /usr/lib/dovecot/deliver" echo "Restarting Dovecot..." service dovecot restart && echo "Dovecot restarted." @@ -210,7 +237,10 @@ echo echo echo printf "Record Name\\tRecord Type\\tText of entry\\n" +# the DKIM record is this one printf "%s._domainkey\\tTXT\\t\\tv=DKIM1; k=rsa; %s\\n" "$subdom" "$pval" +# the SPF record is this one +printf "%s\\tTXT\\t\\tv=spf1 mx a:%s -all\\n" "@" "$maildomain" echo echo echo "$pval" |