#!/bin/bash ############################################################## # File Name: /sources/mail.sh # Version: V1.0 # Author: sanshi # Organization: https://www.9133w.cn/sources/ # Created Time : 2022-05-26 09:57:20 # Description: ############################################################## set -e [ $USER != "root" ] && echo 'root needed!' && exit 0 rpm -q mailx || yum install -y mailx echo 'input which mail address to send messages: ' read mail_addr echo 'INPUT smtp server address: ' read smtp_addr echo 'INPUT smtp auth code: ' read auth_code echo 'Please check file /etc/mail.rc to confirm config:' cat << EOF set from=$mail_addr set smtp=smtps://$smtp_addr:465 set smtp-auth-user=$mail_addr set smtp-auth-password=$auth_code set smtp-auth=login set ssl-verify=ignore set nss-config-dir=/root/.certs EOF echo 'do has these infos?(y/n)' read ans case $ans in y|Y|yes|YES|Yes|YEs|YeS|yES|yeS) echo 'you have already config them.' exit ;; n|N|No|NO|nO) cat >> /etc/mail.rc << EOF set from=$mail_addr set smtp=smtps://$smtp_addr:465 set smtp-auth-user=$mail_addr set smtp-auth-password=$auth_code set smtp-auth=login set ssl-verify=ignore set nss-config-dir=/root/.certs EOF [ -d /root/.certs ] || mkdir -p /root/.certs echo -n | openssl s_client -connect $smtp_addr:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/mail.crt && \ chmod +x /root/.certs/mail.crt && \ certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/mail.crt && \ certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/mail.crt && \ certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ~/.certs -i ~/.certs/mail.crt && \ certutil -L -d /root/.certs if [ $? -eq 0 ] then echo 'mail config finish,please check it.' else echo 'mail CA set failure,but you also can send mail.' exit 1 fi ;; *) echo 'unknown choice.' exit 2 esac