473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Web mail script

I have a simple mail script designed to use from command line.
I want create a simple web interface to use this script as remotely
hosted webscript, from webhost.
The script contains two files- Data File.dat(which holds the list of
email addresses, where the mail has to be sent;
the addresses are separated by new lines); and Message template
File.template(this file contains the message template to be sent.)
Need some help and advices.
thanks
------------------------

#!/usr/bin/perl -w

#user configuration begin#

$mailprg = "/usr/sbin/sendmail"; #path to your mail program
$delay = 0.25; #delay in seconds
$from = 'Coname<so******@domain.com>'; #from address in your mail
$subject = 'Trial send'; #subject of newsletter. u can add the spl
code $USERNAME$
$maildata = "mail.dat"; #mail address file
$msgtemplate = "message.template"; #message template file

#user configuration end#

if(@ARGV){
$i = 0;
while($ARGV[$i]){
if($ARGV[$i] eq "--help"){
print "Command Line Options:\n\n";
print "-t\tTest how the message will be formatted\n";
print "-d\tData file listing the email addresses\n";
print "-m\tMessage template file\n";
print "-s\tSubject\n";
print "-f\tFrom address. Quote for security reasons\n";
die "\nMore information at indiWiz.com\n";
}
elsif($ARGV[$i]=~/^-/){
$arr = substr($ARGV[$i],1,1);
if($arr eq "d"){
$maildata = $ARGV[$i+1];
$i+=2;
}
elsif($arr eq "m"){
$msgtemplate = $ARGV[$i+1];
$i+=2;
}
elsif($arr eq "t"){
$testflag = 1;
$i++;
}
elsif($arr eq "s"){
$subject = $ARGV[$i+1];
$i+=2;
}
elsif($arr eq "f"){
$from = $ARGV[$i+1];
$i+=2;
}
else{
die "Wrong argument!";
}
}
}
}

open TEMPLATE, $msgtemplate || die "Cannot open template file!\n";
while(<TEMPLATE>){
$msg .= $_;
}
close TEMPLATE || die "Cannot close template file!\n";

open MAILFILE,"$maildata" || die "Cannot open data file!\n";
while(<MAILFILE>){
chomp($_);
@arr = split(/\@/,$_);
$arr[0] = ucfirst($arr[0]);
$tmp = $msg;
$tmp =~ s/\$USERNAME\$/$arr[0]/g;
$subject =~ s/\$USERNAME\$/$arr[0]/g;
$temp = "To: $arr[0]<$_>\n";
$temp .= "From: $from\n";
$temp .= "Subject: $subject\n\n\n";
$temp .= $tmp;
if($testflag){
print $temp;
last;
}
else{
open MAILPRG,"|$mailprg -t" || die "Cannot open mail program!\n";
print MAILPRG $temp;
close MAILPRG || die "Cannot close mailprogram!\n";
if($delay < 0){
$delay = 1;
sleep $delay;
}
elsif($delay < 1){
select(undef,undef,undef,$delay);
}
else{
sleep $delay;
}
print $_,"\n";
}
}
close MAILFILE || die "Cannot close data file!\n";
Jul 19 '05 #1
3 4050
trend5 wrote:
Need some help and advices.
What advice are you asking for? Your post did not show
1) what the program generated when you ran it
2) what you expected it to do.
if(@ARGV){
$i = 0;
while($ARGV[$i]){
if($ARGV[$i] eq "--help"){ print;print;print }
elsif($ARGV[$i]=~/^-/){
$arr = substr($ARGV[$i],1,1);
if ($arr eq "d"){$maildata = $ARGV[$i+1]; $i+=2;}
elsif($arr eq "m"){$msgtemplate = $ARGV[$i+1]; $i+=2;}
elsif($arr eq "t"){$testflag = 1; $i++;}
elsif($arr eq "s"){$subject = $ARGV[$i+1]; $i+=2;}
elsif($arr eq "f"){$from = $ARGV[$i+1]; $i+=2;}
else{ die "Wrong argument!"; }
}
}
}
That's a mighty ugly bunch of C code there.
When creating Perl programs, you should program in Perl, not C.

my $Usage = <<EOM;
Command Line Options:
-t Test how the message will be formatted
-d Data file listing the email addresses
-m Message template file
-s Subject
-f From address. Quote for security reasons

More information at indiWiz.com
EOM
if (@ARGV and $ARGV[0] =~ /^-/) {
$_ = shift;
die $Usage if $_ eq '--help';
my $opt = substr $_,1,1;
if ($opt eq "d") { $maildata = shift; }
elsif ($opt eq "m") { $msgtemplate = shift; }
elsif ($opt eq "t") { $testflag = 1; }
elsif ($opt eq "s") { $subject = shift; }
elsif ($opt eq "f") { $from = shift; }
else { die "Invalid option '$_'\n",$Usage; }
}
die "Unexpected command line arguments '@ARGV'\n",$Usage if @ARGV;
open TEMPLATE, $msgtemplate || die "Cannot open template file!\n";
open TEMPLATE, $msgtemplate or
die "Cannot open template file $msgtemplate - $!\n";
$subject =~ s/\$USERNAME\$/$arr[0]/g;


That will work only once. You need to keep the original around.

(my $newsubject = $subject) =~ s/\$USERNAME\$/$arr[0]/g;

If you have any more questions, specific ones regarding perl, then
post them to the comp.lang.perl.misc newsgroup.
(comp.lang.perl is defunct; superceded by comp.lang.perl.misc)

-Joe
Jul 19 '05 #2
PC

"Joe Smith" <jo*@inwap.com> wrote in message
news:Ad********************@comcast.com...

(comp.lang.perl is defunct; superceded by comp.lang.perl.misc)


Why?
Jul 19 '05 #3
PC wrote:
"Joe Smith" <jo*@inwap.com> wrote in message
news:Ad********************@comcast.com...
(comp.lang.perl is defunct; superceded by comp.lang.perl.misc)


Why?


The original comp.lang.perl was split into several new newsgroups.
This was voted on many many years ago.
There is a lot more traffic in comp.lang.perl.misc than comp.lang.perl .
-Joe
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: pee2pee | last post by:
Hi, I have below code: <html> <head> <title>Contacting Worldpay, Please wait.......</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body...
1
by: Frank R. Suchy | last post by:
Hi there, the task: Any mail that drops into a specified mailbox shall cause a (php-)script to immediately react with some action. Quite a common task, isn't it? I could use e.g. cron to let...
3
by: Remon Huijts | last post by:
Hi, When I use php mail() in a script on my localhost to send an HTML message to an e-mailaccount on my online host, all is fine. When I use php mail() in a script on my online host to send an...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
1
by: Joe via DotNetMonster.com | last post by:
Hi, I'm trying out a test mail script but it doesn't seem to work. The error I get is that mail is not declared on the mail.To line. Also, do I need to specify the SMTP Server? I have it...
0
by: job kazan | last post by:
Can anyone suggest the best and easiest platform for the following job, possible freelancer and approximate budget for this: "It must be a script that has as an input a long code from the...
11
by: fdu.xiaojf | last post by:
Hi, I just want to send a very simple email from within python. I think the standard module of smtpd in python can do this, but I haven't found documents about how to use it after googleing....
3
uranuskid
by: uranuskid | last post by:
Hey folks, I was going to include a contact form on my website. Well, in the first place that seemed an easy thing to do with a form that prompts a PHP file validating the input vaiables and using...
2
krik
by: krik | last post by:
Hello, I would like to send a mail via a script with customized From field or at least with Reply-To. This email is sent by a monitoring server via a cron job and the users should see this mail as...
6
by: Call Me Tom | last post by:
The following simple script receives data from a form and sends me an email. It works fine on my testing machine (xampp for windows). However, when I upload it to my web host, the script processes...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.