Author: belltoy | statement: reprinted. The original address and author information and copyright statement must be indicated in hyperlink form during reprinting.
Web: http://www.belltoy.net/send-mail-with-perl.html
It's boring to sign in emails when you are on a business trip ~
When I watched the European Championship in the previous paragraph, the time difference has not been adjusted. I cannot start Zzzzz in the morning.
But there are policies and countermeasures.
I wrote a Perl script on the server, sent an email using net: SMTP, and ran it regularly using crontab. Then I solved the problem. Haha
Perl script:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
#! /Usr/bin/perluse 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 ($ 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 the command line parameter 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 blank lines} # send the 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> zzq@nlgx.dmp 000000 qiandao@nlgx.dmp sign-in
Then the automatic running time is configured in crontab:
# Hour, day, month, week, command 41 8 ** 1-5/usr/bin/perl/home/AIG /. run/checkin. PL/home/AIG /. run/mails. conf58 13 ** 1-5/usr/bin/perl/home/AIG /. run/checkin. PL/home/AIG /. run/mails. conf