# These codes are written in 2003 package Mnsend; use Net::SMTP; use MIME::Base64; use strict; ### Modify email address and password first ############# ### at line like: $Smtp->auth('vvvvvv@gggg.com','yyyyyyy'); # # SendAlert(HP,'Example','hello,world!','a@163.com,b@163.com'); ########################################################## # Encoding head,if your mother language is English # replace "=?GB2312?B?".$name."?=" with $name sub headerconvert{ my $name=shift; $name = encode_base64($name); chomp($name); return $name = "=?GB2312?B?".$name."?="; } sub mailheaderconvert{ my $name=shift; my ($first,$second)=($name=~m/^(.+)<(.+)>/); $first=headerconvert($first); $name="\"$first\"<$second>"; } sub SendAlert { my( $name, $subname, $Message, $List ) = @_; # rewrite message here $name = mailheaderconvert($name); my $alert = headerconvert($subname); # The html body is same as text,it is just a example. # In real world,$htmlmsg may be 'hello,world' # the $testmsg may be 'hello,world!' my $textmsg = encode_base64($Message); my $htmlmsg = encode_base64($Message); foreach my $Recipient ( @$List ) { my $Smtp; my( $Host ) = ( $Recipient =~m/\@(.*)/ ); #if your mail address suffix is not same as your mail server name #uncomment code below #my $Host = "your mail server name"; #print "Sending message to $Recipient...at $Host..."; if( $Smtp = new Net::SMTP( $Host ) ) { # modify the email address and password at your will. $Smtp->auth('vvvvvv@gggg.com','yyyyyyy'); $Smtp->mail($ENV{USER}); #print $Smtp->domain,"\n"; #begin mail $Smtp->mail( "Perl Pager" ); $Smtp->to( $Recipient ); #only for address $Smtp->data(); #$Smtp->datasend( "Date: Tue, 15 Jul 2003 15:32:19 +0800\n" ); my @body=@{&getbody($name,$Recipient,$alert,$textmsg,$htmlmsg)}; foreach my $bodyline (@body){ $Smtp->datasend($bodyline); } $Smtp->dataend(); $Smtp->quit(); } else { print "failed\n"; `net send localhost "Mnsend"`; return undef; } print "success\n"; } return 1; } sub getbody { my @body=undef; my ($name,$Recipient,$alert,$textmsg,$htmlmsg)=@_; $body[0]="From: $name\n"; $body[1]="To: $Recipient\n"; $body[2]="Subject: $alert\n"; $body[3]="MIME-Version: 1.0\n"; $body[4]="Content-Type: multipart/alternative;\n"; $body[5]=" boundary=\"----=_NextPart_000_0017_01C34AE6.494814A0\"\n"; $body[6]="X-Priority: 3\n"; $body[7]="X-MSMail-Priority: Normal\n"; $body[8]="X-Mailer: Microsoft Outlook Express 5.50.4522.1200\n"; $body[9]="X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200\n"; $body[10]="\n"; $body[11]="This is a multi-part message in MIME format.\n"; $body[12]="\n"; $body[13]="------=_NextPart_000_0017_01C34AE6.494814A0\n"; $body[14]="Content-Type: text/plain;\n"; $body[15]=" charset=\"gb2312\"\n"; $body[16]="Content-Transfer-Encoding: base64\n"; $body[17]="\n"; $body[18]="$textmsg\n"; $body[19]="------=_NextPart_000_0017_01C34AE6.494814A0\n"; $body[20]="Content-Type: text/html;\n"; $body[21]=" charset=\"gb2312\"\n"; $body[22]="Content-Transfer-Encoding: base64\n"; $body[23]="\n"; $body[24]="$htmlmsg\n"; $body[25]="\n"; $body[26]="------=_NextPart_000_0017_01C34AE6.494814A0--\n"; $body[27]="\n"; return \@body; } 1;