Alarm using Java email on Linux Server

Source: Internet
Author: User

Alarm using Java email on Linux Server

Here we will share with you how the Linux server uses Java to send email alerts.

Prerequisites: the server first installs and configures the java environment.

I. installation in the JAVA environment

[Root @ Server2 ~] # Tar-zxvf jdk-7u75-linux-x64.gz-C/usr/local

[Root @ Server2 ~] # Vi/etc/profile

Export JAVA_HOME =/usr/local/jdk1.7.0 _ 75

Export JRE_HOME =$ {JAVA_HOME}/jre

Export CLASSPATH =. :$ {JAVA_HOME}/lib :$ {JRE_HOME}/lib

Export PATH =$ {JAVA_HOME}/bin: $ PATH

[Root @ Server2 ~] # Source/etc/profile Quick Start

[Root @ Server2 ~] # Java-version

Java 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)

Ii. script configuration

Upload the script directory in the attachment to/var/scripts and decompress it.

Modify tomail. sh

#! /Bin/bash

Export LANG = en_US.UTF-8

HOST = "smtp.163.com"

SENDER = "monitor@163.com"

PASSWORD = "xxxxxxxx"

Extends ER = "youremail@yourdomain.com"

# Alarm content

SUBJECT = "request timeout, Please check"

CONTENT = "this eamil from monitor server"

# Send an email

/Usr/local/jdk1.7.0 _ 75/bin/java-cp/var/scripts/monitor: /var/scripts/lib/* SendMails $ HOST $ SENDER $ PASSWORD "$ SUBJECT" "$ CONTENT" $ author er


After the configuration, execute tomail. sh to send the email.

If the following error is reported, configure the 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)

[Root @ Server2 ~] # Vi/etc/hosts

127.0.0.1 localhost. localdomain localhost4 localhost4.localdomain4

: 1 localhost. localdomain localhost6 localhost6.localdomain6

192.168.1.22 Server2

Attachment java to mail Download:

------------------------------------------ Split line ------------------------------------------

Free in http://linux.bkjia.com/

The username and password are both www.bkjia.com

The specific download directory is in the/June/OCTOBER/Linux Server alert trigger by using Java email/

For the download method, see

------------------------------------------ Split line ------------------------------------------

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.