#!/usr/bin/perl # # This script will enable you to send simple mails to a recipient # usage: sendmail -r foo@bar.com -s "some mail title" -t "mail body goes here" # requires: libnet-smtpauth-perl # In order to work properly, you need to configure the settings below # # author: rakudave@gmx.net # website: www.rakudave.ch # # last update: 27.09.2008 ########################## EDIT BELOW ########################## my $user = ''; # username (bar) my $pass = ''; # password (****) my $host = '''; # smtp server (smtp.foo.com) my $from = ''; # "from"-address (bar@foo.com) ######################### STOP EDITING ######################### use strict; use Net::SMTP; use Net::SMTP_auth; use Getopt::Std; use vars qw($opt_r $opt_s $opt_t); # check arguments getopts('dr:s:t:'); if(!$opt_r or !$opt_s or !$opt_t){print "fatal: recipient (-r), subject (-s) or text (-t) are not declared\n";exit;} # create smtp object my $smtp = Net::SMTP_auth->new($host); # login to smtp $smtp->auth('LOGIN', $user, $pass); # send the mail print sender($opt_r, $opt_s, $opt_t), "\n"; #done $smtp->quit; exit; ########### # send mail sub sender{ my($rcpt, $subject, $msg) = @_; $smtp->mail(); $smtp->to($rcpt); $smtp->data(); $smtp->datasend("From: $from\n"); $smtp->datasend("To: $rcpt\n"); $smtp->datasend("Subject: $subject\n\n"); # end header $smtp->datasend("$msg\n"); $smtp->dataend(); return("successfully sent mail to $rcpt"); } __END__