Perl script:
#! /Usr/bin/perl
Use Net: SMTP;
Use MIME: base64;
################
# Automatic sign-in script #
################
$ Host = '10. 182.131.153 '; # SMTP server address
###########################
#
# $ HOST: SMTP Server
# $ Auth: email account
# $ Password: email account password
# $ To: target to be sent
# $ Mail_body: email content
#
###########################
Sub send_mail {
My ($ host, $ auth, $ password, $ to, $ mail_body) = @_;
My $ SMTP = net: SMTP-> New (
Host => $ host,
Hello => $ host,
Timeout => 30,
DEBUG => 1
);
$ SMTP-> auth (substr ($ auth, 0, index ($ auth, '@'), $ password );
$ SMTP-> mail ($ auth );
$ SMTP-> to ($ );
$ SMTP-> bcc ($ auth );
$ SMTP-> data ();
$ SMTP-> datasend ("Content-Type: text/plain; charset = gb2312 \ n ");
$ SMTP-> datasend ("content-transfer-encoding: base64 \ n ");
$ SMTP-> datasend ("from: $ auth \ n ");
$ SMTP-> datasend ("to: $ to \ n ");
$ SMTP-> datasend ("Subject: =? Gb2312? B? ". Encode_base64 ($ mail_body ,'')."? = \ N ");
$ SMTP-> datasend ("\ n ");
$ SMTP-> datasend (encode_base64 ($ mail_body, '')." \ n ");
$ SMTP-> dataend ();
$ SMTP-> quit;
}
# Obtain command line parameters
If (@ argv <1 ){
$ Conf_file = './mailusers. conf'; # Default Configuration File
}
Else {
$ Conf_file = $ argv [0]; # Get the configuration file name
}
# Open the configuration file and Log File
Open conf_file, $ conf_file or die "Open config file [$ conf_file] failed! \ N ";
Open LOG_FILE, '> send. log' or die "open send. log failed! $! \ N ";
While (<LOG_FILE> ){
Chomp;
If ($ _ = ~ /^ # + /){
Next; # Skip the comment line
}
@ Line = Split/\ s +/, $ _;
If (@ line! = 4 ){
Next; # Skip empty rows
}
# Send an email
Send_mail ($ host, $ line [0], $ line [1], $ line [2], $ line [3]);
Print LOG_FILE "[". localtime (). "] send_mail ($ host, $ line [0], $ line [1], $ line [2], $ line [3]); \ n ";
}
Close conf_file;
Close LOG_FILE;
The account and target of the automatic mail are configured in the configuration file. The configuration file format is mails. conf:
# <Auth> <password> <to> <mail body>
000000 sign in and then configure automatic run time in crontab:
# Hour, day, month, and week commands
41 8 ** 1-5/usr/bin/perl/home/AIG/. Run/checkin. pl/home/AIG/. Run/mails. conf
58 13 ** 1-5/usr/bin/perl/home/AIG/. Run/checkin. pl/home/AIG/. Run/mails. conf