Use sendmail to send emails

Install sendEmail

    sendEmail is a free, lightweight, command-line SMTP mail client.

    If you need to send emails from the command line, sendEmail is the perfect choice: simple to use and powerful.

wget -P /tmp 
# install components
yum install perl-Net-SSLeay perl-IO-Socket-SSL -y
# Unzip the compressed package and copy the command to /usr/local/ bin
tar -zxvf /tmp/sendEmail-v1.56.tar.gz -C /tmp
cp /tmp/sendEmail-v1.56/sendEmail /usr/local/bin/
chmod +x zabbix:zabbix /usr/local/bin/sendEmail

3. Create the zabbix alarm script directory

mkdir -p /usr/local/zabbix/alertscripts
chown -R zabbix:zabbix /usr/local/zabbix/alertscripts
4. Modify the zabbix server configuration file to specify the script directory
vim /usr/local/zabbix/etc/zabbix_server.conf
# Modify the AlertScriptsPath variable as follows, about line 448
AlertScriptsPath=/usr/local/zabbix/alertscripts

5. Test sendEmail to send emails (choose one of the two steps from step 6)


#Command line test as follows:
# sendEmail -f from @ 163 .com -t [email protected] -s smtp. 163 .com -u ' test ' -o message-content-type=html -o message-charset= utf8 -xu from @ 163 .com -xp ' passwd ' -m ' test ' # A prompt appears to prove that the command is installed correctly:
Dec 24 23:01:59 zabbix sendEmail[3612]: Email was sent successfully! # If you receive this prompt, it means the sending is successful # -f from @ 163 .com # sender email address # - t [email protected] # recipient email address # -s smtp. 163 .com # The smtp server address of the sender's mailbox # -u ' test ' # email header # -o message-content-type= html # Mail content format is html # -o message-charset= utf8 # Mail content encoding is utf8 # -xu from @ 163 .com # Sender email login username # -xp ' passwd ' # Sender email login password # -m ' test ' # email content # Write email alert script vim /usr/local/zabbix/alertscripes/sendEmail.sh #!/bin/bash to=$1 subject=$2 message=$3 smtp_server="smtp.163.com" /usr/local/bin/sendEmail -f from@163.com -t "$to" -s "$smtp_server" -u "$subject" -o message-content-type=html -o message-charset=utf8 -xu from@163.com -xp "passwd" -m "$message" chmod +x sendEmail.sh chown zabbix.zabbix sendEmail.sh

 

 

6. Use 163 proxy to send mail (choose one from step 5)

yum install -y mailx
# Add two lines of 163 authentication at the bottom of the file
vim /etc/mail.rc
# Set sender address, smtp server
set from=pyslinux@163.com smtp=smtp.163.com
# Set the sender's smtp authentication user name and password (because 163 opens smtp after the authorization code is set here instead of the login password)
set smtp-auth-user=pyslinux@163.com smtp-auth-password=密码 smtp-auth=login
# test email sending
mail -s 'test' [email protected] < /etc/passwd
# write script
vim /usr/local/zabbix/alertscripes/mail.sh
 
#!/bin/bash
echo "$3"|mail -s "$2"  "$1"
 
chmod +x /usr/local/zabbix/alertscripes/mail.sh

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325036857&siteId=291194637