Share here how the server uses Java Mail alerts
Premise: The server first installs the configuration good Java environment
I. Installation of the Java environment
[[email protected] ~]# tar -zxvf Jdk-7u75-linux-x64.gz -c /usr/local[[email protected] ~]# vi /etc/profileexport java_home=/usr/local/jdk1.7.0_75export jre_home=${java_home}/jreexport classpath=.:${java_home }/lib:${jre_home}/libexport path=${java_home}/bin: $PATH [[email protected] ~]# source /etc/profile fast entry [[email protected] ~]# java -versionjava version "1.7.0_45" openjdk runtime environment (RHEL-2.4.3.3.EL6-X86_64 U45-B15) OpenJDK 64-bit server vm (Build 24.45-b08, mixed mode)
Second, the script configuration
Upload the script directory in the attachment to/var/scripts after unpacking
Modify Tomail.sh
#!/bin/bashexport Lang=en_us. Utf-8host= "smtp.163.com" sender= "[email protected]" password= "xxxxxxxx" receiver= "[email protected]" #报警内容 subject= " Request Timeout,please Check "content=" This eamil from monitor server "#发送邮件/usr/local/jdk1.7.0_75/bin/java- cp/var/scripts/monitor:/var/scripts/lib/* sendmails $HOST $SENDER $PASSWORD "$SUBJECT" "$CONTENT" $RECEIVER
Once configured, execute tomail.sh to send mail.
If the following error is reported, configure the next hosts
Javax.mail.SendFailedException:Sending failed;
Nested exception is:
Class javax.mail.messagingexception:501 Syntax:helo hostname
At Javax.mail.Transport.send0 (transport.java:218)
At Javax.mail.Transport.send (transport.java:80)
At Mailutil.send (mailutil.java:44)
At Sendmails.main (sendmails.java:36)
[Email protected] ~]# vi/etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.1.22 Server2
This article is from the "xiangcun168" blog, make sure to keep this source http://xiangcun168.blog.51cto.com/4788340/1692765
Linux Server alerts using Java Mail alerts