Tomcat monitoring series-send emails

Source: Internet
Author: User

Tomcat monitoring series-send emails

As mentioned in the previous article, the mail sending function is implemented. When the monitoring software detects an exception, it calls the restartServer. bat file to execute the specified command. When selecting to implement this function, I first thought of a good tool Blat for sending mail via command line. It is very easy to use this tool to send mail. Here is a brief introduction.

1. Implement blat mail sending

Download blat can go to the official website: course you can also go to the Internet under Baidu, there will be a lot of download resources.

After downloading and decompress the package, find a few files and put them under C: \ WINDOWS \ system32. In this way, you can directly call them through the command line.

Put it in the specified path and open a command line window. Entering blat will output the following information, indicating that blat can be used.

Here we use blat to send emails. The first is a batch processing:

Sendmail. bat:


@ Echo off :::::::::::::: set from = [sender address] set user = test [Sender account] set pass = testpwd [Sender Password] set tf1_mail_list.txt [recipient list] set subj = This is the mail title ha [mail title] set mail=mail_body.txt [mail content] set attach = c: \ sendmail \ fj.txt [email attachment] set server = [sending server] set debug =-debug-log blat. log-timestamp [log] ::::::::::::::: execute blat ::::::::::::::: blat % mail %-tf %-base64-charset UTF8-subject % subj %-attach "% attach %"-server %-f % from %-u % user %-pw % pass % debug %



This email come from,Congratulations!




I am fj! Test Chinese


Note:1. The used mailbox must support smtp. For example, smtp is not enabled by default in 163. You need to enable it in configuration.

2,The sender address and the sender account must be distinguished,The sender's account must not be suffixed with "@". Otherwise, a logon Failure error is reported.

3. I wrote the above email address and password at will. Please use the correct email address and password for actual use.

After configuring the preceding information, double-click sendmail. bat. If no error message is returned, you can check your inbox. You should have received the email you just sent.

2. Use VBS scripts to send emails

Now there is no problem with sending emails via blat, but during the test, we found that the Monitoring Assistant of Tomcat Moni described above could not call sendmail. the bat file cannot be executed normally after the call, but it can be executed normally if you replace the bat file with other commands. After trying for a long time, I still failed to send emails normally by calling sendmail. bat through the Monitoring Assistant of TomcatMoni. However, you can manually double-click sendmail. bat to send an email. Then I found the second method of sending mail to be introduced next, and sent it through the vbs script, as shown in the following example:

Sendmail. vbs


NameSpace = "" set Email = CreateObject ("CDO. message ") Email. from = "" [sender address] Email. to = "" [recipient address] Email. subject = "this is the mail title" [mail title] x = "C: \ atatmonitor \ sendmail \ mail_body.txt" [mail body] y = "C: \ TomcatMonitor \ sendmail \ fj.txt "[Attachment] Set fso = CreateObject (" Scripting. fileSystemObject ") Set myfile = fso. openTextFile (x, 1, Ture) c = myfile. readallmyfile. closeEmail. textbody = cEmail. addAttachment ywith Email. configuration. fields. item (NameSpace & "sendusing") = 2. item (NameSpace & "smtpserver") = "" [email server address ]. item (NameSpace & "smtpserverport") = 25. item (NameSpace & "smtpauthenticate") = 1. item (NameSpace & "sendusername") = "sendtest" [Sender account ]. item (NameSpace & "sendpassword") = "" sendtestpwd "[Password ]. updateend withEmail. sendSet Email = Nothing


Double-click the vbs script to directly send an email. The following example is called during batch processing:

RestartServer. bat:


@ Rem here you can write the command you need to execute @ rem restart tomcat command @ rem sends an email notification wscript C: \ TomcatMonitor \ sendmail. vbs


Modify the conf. properties file of the TomcatMoni Monitoring Assistant and set the startup command called when the server is abnormal to the batch processing file. When the server is abnormal, you will receive an email. Of course, if you have activated the email notification service (for example, email 139) in your mailbox, you can receive SMS notifications in real time.

Now, we will introduce it here today and continue to improve other requirements in the future.

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: 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.