In Linux, use Perl to send emails-Linux Enterprise Application-Linux server application information. The following is a detailed description. I have been very depressed recently. I want to maintain 10 college servers. If the server disk is full or for other reasons, can I find it early? I thought of it. I got a script and monitored the server. If there was an exception, I sent an email to me and it would be OK. I have always wanted to use the built-in sendmail to implement my ideas. Because I am not familiar with sendmail, I have never been able to solve it well. Today, when you look at a website, you can see the method of sending emails using php. I remember that php was not installed when I installed the software, but perl was installed. I used perl to send emails. The process is as follows:
[Root @ CentOS ~] # Ping act0r.bokee.com
PING act0r.bokee.com (58.49.57.34) 56 (84) bytes of data.
64 bytes from 58.49.57.34: icmp_seq = 0 ttl = 54 time = 128 MS
4. Install the module required for sending emails
[Root @ CentOS ~] # Perl-MCPAN-e shell
It is basically a carriage return. Only at the end will you choose your region and country.
Cpan> install Authen: SASL
Cpan> q
5. vi/etc/init. d/sendmail. sh
#! /Usr/bin/perl
Use Net: SMTP;
My $ mailhost = "smtp.163.com"; # SMTP Server
My $ mailfrom = 'notfour @ 163.com '; # your EMAIL address
My @ mailto = ('fayland @ gmail.com ', 'not _ four@hotmail.com'); # recipient's address
My $ subject = "this is the title ";
My $ text = "this is the body \ n the second line is located here. ";
$ Smtp = Net: SMTP-> new ($ mailhost, Hello => 'localhost', Timeout => 120, Debug => 1); # when it is 0, do not output debugging information
# Anth login, type your user name and password here
$ Smtp-> auth ('user', 'pass'); ### user name and password
Foreach my $ mailto (@ mailto ){
# Send the From and Recipient for the mail servers that require it
$ Smtp-> mail ($ mailfrom );
$ Smtp-> to ($ mailto );
# Start the mail
$ Smtp-> data ();
# Send the header
$ Smtp-> datasend ("To: $ mailto \ n ");
$ Smtp-> datasend ("From: $ mailfrom \ n ");
$ Smtp-> datasend ("Subject: $ subject \ n ");
$ Smtp-> datasend ("\ n ");
# Send the message
$ Smtp-> datasend ("$ text \ n ");
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