Created
January 15, 2013 08:08
-
-
Save lysu/4537128 to your computer and use it in GitHub Desktop.
send mail in perl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/perl | |
use strict; | |
use warnings; | |
use POSIX; | |
use Net::SMTP; | |
sub sendMail; | |
my $last_date = strftime("%Y-%m-%d %H:%M:%S",localtime(time() - 25*60*60)); | |
my $content = `mysql -utest -pzzxz -hxxx -uhms -P3307 hms -e' set names utf8;select h.id,h.hotel_seq,h.hotel_name,h.apply_status, l.operate_time from HOTEL_INFO h join hotel_apply_log l on h.id = l.hotel_id where operator = "clusterTask-qhotel-tree-del" and l.operate_time >= "$last_date";'| tail -n+2 `; | |
&sendMail($content, "test title...."); | |
#print $content; | |
sub sendMail { | |
my ($title, $msg) = @ARGV; | |
my $mailhost = "smtp.xx.com"; | |
my $mailfrom = 'notice@xx-info.com'; | |
# the recipient list | |
my @mailto = ('xxx@qq.com'); | |
my $subject = $title; | |
my $text = $msg; | |
my $smtp = Net::SMTP->new($mailhost, Hello => 'localhost', Timeout => 120, Debug => 1); | |
# auth login, type your user name and password here | |
$smtp->auth('gddc@xxx.com','scsd') or die; | |
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\n"); | |
# Send the termination string | |
$smtp->dataend(); | |
} | |
$smtp->quit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment