Autoresponder with header’s sensitivity
Hello!
I am trying to code a script for subscription, but I need some help. Just like a program that is an online vacation reply manager with certain exception. In other words, when someone sends an email to the auto-responder, a follow-up begins depending on the content of the header.
My script will be located in cgi-bin directory on my site. The function of the script will be to check the content of header of incoming email. If subject of the incoming-email contains the words “ultimate brochure ” (case insensitive), the script sends a one-time follow-up email to the subscriber with message in “brochure.txt”. Let us assume that the sender/subscriber of an email to me put a heading like “I will like to subscribe for ultimate brochure”, the cgi-script must be able to scan the heading to see whether “ultimate” and “brochure” are among the words in the heading. Follow-up email is not sent if both “ultimate” and “brochure” words are not within the content of the heading.
My initial code is as below. It will be highly appreciated if somebody can put me through (in the form of coding) in this my endeavour. I thank you very much in advance for your help and enlightenment. hans.adamsson(at)wippies(dot)fi
Best regards,
Hans Adamsson, Finland
NB:
Script file: request.cgi
------------------------
#!/usr/bin/perl
################################
$script_name = 'request.cgi';
$from = 'info@mywebsite.net';
################################
# Path to Sendmail on my server.
$mailprog = '/usr/sbin/sendmail';
##################################
# Advanced Settings Auto Responder
$auto_responder_from = 'info@mywebsite.net';
$auto_responder_message = "brochure.txt";
##################################
# Subscribe Condition: Subject of email MUST contain the following words: ultimate brochure (case insensitive).
$subscribe_subject = "ultimate brochure";
#################################
# MAIN CODING FOR THE SCRIPT! #
#################################
use CGI qw/:standard :cgi-lib/;
@date=localtime();
$date[4]++;
$date[5]+=1900;
$date="$date[5]-$date[4]-$date[3]";
$scount = 0;
$uscount = 0;
$dcount = 0;
%messages = ();
$messages = $pop->list;
foreach $msgid (keys %$messages) {
$mymessage = $pop->get($msgid);
$to = "";
$from = "";
$subject = "";
if($mymessage) {
@mess = @$mymessage;
foreach $line (@mess) {
if ($line =~ m/To: /) {
$line =~ s/To: // unless ($line =~ m/Reply-To:/i);
$line =~ s/<//gm;
$line =~ s/>//gm;
chomp($line);
$to = $line;
}
if ($line =~ m/From: /) {
$line =~ s/From: //;
$line =~ s/<//gm;
$line =~ s/>//gm;
chomp($line);
@lines = split(/ /,$line);
foreach $line2(@lines) {
if($line2 =~ /\@/) { $from = $line2; }
}
}
if($line =~ m/Subject: /) {
$line =~ s/Subject: //;
chomp($line);
$subject = $line;
}
} #done message scan
$mfound = 0;
$to =~ tr/A-Z/a-z/;
$from =~ tr/A-Z/a-z/;
if($to eq $subscribe_email) { &subscribe; }
}
}
sub error
{
my $error = shift;
print <<EOF;
<title>Error</title>
Error: $error
EOF
exit;
}
Autoresponder with header’s sensitivity
Code:
#!/usr/bin/perl
##################################################
$script_name = 'request.cgi';
$from = 'info@mywebsite.net';
##################################################
# Path to Sendmail on my server.
$mailprog = '/usr/sbin/sendmail';
##################################################
# Advanced Settings Auto Responder
$auto_responder_from = 'info@mywebsite.net';
$auto_responder_message = "brochure.txt";
##################################################
# Subscribe Condition: Subject of email MUST contain the following words: ultimate brochure (case insensitive).
$subscribe_subject = "ultimate brochure";
####################################
# MAIN CODING FOR THE SCRIPT! #
####################################
use CGI qw/:standard :cgi-lib/;
@date=localtime();
$date[4]++;
$date[5]+=1900;
$date="$date[5]-$date[4]-$date[3]";
$scount = 0;
$uscount = 0;
$dcount = 0;
%messages = ();
$messages = $pop->list;
foreach $msgid (keys %$messages) {
$mymessage = $pop->get($msgid);
$to = "";
$from = "";
$subject = "";
if($mymessage) {
@mess = @$mymessage;
foreach $line (@mess) {
if ($line =~ m/To: /) {
$line =~ s/To: // unless ($line =~ m/Reply-To:/i);
$line =~ s/<//gm;
$line =~ s/>//gm;
chomp($line);
$to = $line;
}
if ($line =~ m/From: /) {
$line =~ s/From: //;
$line =~ s/<//gm;
$line =~ s/>//gm;
chomp($line);
@lines = split(/ /,$line);
foreach $line2(@lines) {
if($line2 =~ /\@/) { $from = $line2; }
}
}
if($line =~ m/Subject: /) {
$line =~ s/Subject: //;
chomp($line);
$subject = $line;
}
} #done message scan
$mfound = 0;
$to =~ tr/A-Z/a-z/;
$from =~ tr/A-Z/a-z/;
if($to eq $subscribe_email) { &subscribe; }
}
}
sub error
{
my $error = shift;
print <<EOF;
<title>Error</title>
Error: $error
EOF
exit;
}
Autoresponder with header's sensitivity
Hi Sixtease,
The code is not working. I configured the script's code to my site information. Then I uploaded the script onto my website. I chmod the script (which I named "responder.pl") 755. I chmod "brochure.txt" 777. Then I sent email from another email-address to my site's email-address. I put "ultimate brochure" as the heading of the email. I did not get any reply from the "responder.pl" from my website.
Is there some code missing in the above code you supplied?
If I may explicitly restate what I will like to achieve, I am looking for an autoresponder - A script for receiving a mail and immediately replying, depending on content of the header.
My script will be residing in cgi-bin directory on my site. The function of the script will be to check the content of header of incoming email. If subject of the incoming-email contains the words “ultimate brochure” (case insensitive), the script sends a one-time follow-up email to the subscriber with message in “brochure.txt”. Follow-up email is not sent if both “ultimate” and “brochure” words are not within the content of the heading.
Again I thank you very much in advance for your help and enlightenment.
Best regards,
Hans Adamsson
Autoresponder with header's sensitivity
Hi Sixtease,
I am still an amateur and new writing Perl script. However, I am trying to learn fast. Please which program should I use to run the code on command line and debug it.
Best regards,
Hans Adamsson, Finland
Autoresponder with header's sensitivity
Hello Sixtease,
The initial code I posted was not written by me. Going through all the CGI/Perl codes I could found on the internet, I tried to formulate something towards my intended autoreponder. The expression { $pop->list} has no justification. The initial code did not work since I am new to programming in Perl language.
The incoming emails are supposed to come from subscribers any where around the world. Subscribers send emails to, say, info@mywebsite.net on my website. When the subscribers send emails to me, the “responder.pl” (in the cgi-bin directory on my website) processes the emails. The “responder.pl” must be able to check whether there is “ultimate brochure” in the content of the header. If the outcome is true, a one-time followup email is sent to the subscriber.
Please can you provide me with some solution/code about this “get_list_of_messages” function. I thank you very much in advance.
Best regards,
Hans