| 1 | #!/usr/bin/perl |
|---|
| 2 | # Simple script tp send emails |
|---|
| 3 | # Copyright 2007 Alan Baghumian, GNU/GPL |
|---|
| 4 | # |
|---|
| 5 | # Updated: 2007-11-25 10:27 +330 GMT |
|---|
| 6 | # |
|---|
| 7 | |
|---|
| 8 | if ($#ARGV != 3) { |
|---|
| 9 | print "Usage: sendmail.pl <mail-from> <mail-to> <subject> <message> \n"; |
|---|
| 10 | exit; |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | $MailFrom = $ARGV[0]; |
|---|
| 14 | $MailTo = $ARGV[1]; |
|---|
| 15 | $Subject = $ARGV[2]; |
|---|
| 16 | $Message = $ARGV[3]; |
|---|
| 17 | |
|---|
| 18 | $ServerName = "localhost" ; |
|---|
| 19 | |
|---|
| 20 | use Net::SMTP; |
|---|
| 21 | |
|---|
| 22 | # Get the a ll the values for current time |
|---|
| 23 | ($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime(time); |
|---|
| 24 | $DateTime = sprintf "%4d/%02d/%02d %02d:%02d:%02d",$Month+1,$Day,$Year+1900,$Hour,$Minute,$Second; |
|---|
| 25 | |
|---|
| 26 | # Connect to the server |
|---|
| 27 | $smtp = Net::SMTP->new($ServerName) ; |
|---|
| 28 | die "Couldn't connect to server" unless $smtp ; |
|---|
| 29 | |
|---|
| 30 | # DEBUG, Mail is not being sent? |
|---|
| 31 | #$smtp = Net::SMTP->new($ServerName, Debug => 1,) ; |
|---|
| 32 | #print $smtp->banner; |
|---|
| 33 | |
|---|
| 34 | $smtp->mail( $MailFrom ) ; |
|---|
| 35 | $smtp->to( $MailTo ) ; |
|---|
| 36 | |
|---|
| 37 | # Start the mail |
|---|
| 38 | $smtp->data() ; |
|---|
| 39 | |
|---|
| 40 | # Send the header. |
|---|
| 41 | $smtp->datasend("Subject: $Subject\n") ; |
|---|
| 42 | $smtp->datasend("Date: $DateTime\n") ; |
|---|
| 43 | $smtp->datasend("From: $MailFrom\n") ; |
|---|
| 44 | $smtp->datasend("To: $MailTo\n") ; |
|---|
| 45 | $smtp->datasend("\n") ; |
|---|
| 46 | |
|---|
| 47 | # Send the message |
|---|
| 48 | $smtp->datasend("$Message") ; |
|---|
| 49 | |
|---|
| 50 | # Send the termination string |
|---|
| 51 | $smtp->dataend() ; |
|---|
| 52 | |
|---|
| 53 | $smtp->quit() ; |
|---|
| 54 | |
|---|
| 55 | #print "Email has been sent to $MailTo...\n"; |
|---|