|
-
Jun 2nd, 2001, 11:39 PM
#1
Thread Starter
Member
Ssending mail from VB
Hello,
I have a website with a Perl sendmail script set up.
I want to know if I can access the script using
Winsock or some other control from my VB programs
and send mail to an email address using the Perl script.
Thanks a lot for helping out.
Mel.
-
Jun 5th, 2001, 01:58 AM
#2
Lively Member
try this
<A href="mailto:the address @ dot com">
-
Jun 6th, 2001, 12:50 PM
#3
Addicted Member
The idea you need is to construct an HTTP header with the information the script needs already it it, then connect to the website on port 80 using the Winsock control and send it. If you could post the HTML code that interfaces with the Perl script on your website, I could get you started writing an appropriate HTTP header
Things I've Said:
"Life's funny like that...elephants can wear frilly lace panties, and Dubya still looks like a monkey in a big chair"
"Take four goats and strap one to each foot of a llama. Presto, goat-powered llama!"
"You want to get me to work more, get me a Coke. No? Then deal with inferior garbage, I'm not coding another line and your clients can go to......thanks, I'd love a Coke right about now!"
-
Jun 6th, 2001, 02:50 PM
#4
Thread Starter
Member
I already know how to connect to the server from VB.
When I send a string without any & or = signs, it
works fine. But when it has one of those characters,
it screws up since it thinks that it's a new variable.
However, I can replace all the & and = signs to something
else like ### or anything. Like,
Replace (String1,"&","###")
Replace (String1,"=","&&&")
Then I can modify the Perl script to convert this back
to it's original state. So basically I'm asking a Perl
question. Do you know how to replace ### to & signs in Perl?
I'm very new to Perl so I don't know how to do this.
-
Jun 6th, 2001, 03:00 PM
#5
Addicted Member
Not specifically, but all to encode "special characters" like an equals sign or anything that isn't a number or a letter, URLs encode them with a percent sign and the ASCII hexadecimal value of the character.
Example:
"Him & her" becomes "Him%20%26%20her", where "%20" encodes the spaces (ASCII decimal 32, hex 20) and "%26" encodes the ampersand (ASCII decimal 38, hex 26)
Hope this helps!
Things I've Said:
"Life's funny like that...elephants can wear frilly lace panties, and Dubya still looks like a monkey in a big chair"
"Take four goats and strap one to each foot of a llama. Presto, goat-powered llama!"
"You want to get me to work more, get me a Coke. No? Then deal with inferior garbage, I'm not coding another line and your clients can go to......thanks, I'd love a Coke right about now!"
-
Jun 6th, 2001, 03:23 PM
#6
Thread Starter
Member
Yeah, that's exactly what I want to do.
I can encode & signs to %26 or something.
For example:
Replace (String1,"&","%20")
Then I'll post it to the Perl script from VB:
Postdata = "name=" + string1 + "&address=" + string2
What I want to know is how do you convert
a %20 in a variable like string1 back to & in Perl.
So I want to know the Perl equivalent to the
Replace function in VB. How do you replace characters
in a Perl script???
-
Jun 6th, 2001, 03:31 PM
#7
Addicted Member
Haven't the slightest, I don't use Perl. But I know someone who's really good at it, and I'm sure could help.
Email [email protected]. This is my college roomie Russ Graves, and he's been into Perl for quite a while. Tell him that Chris Sammis recommended that he ask you, and I'm sure he'll get back to you as soon as he can with an answer
Things I've Said:
"Life's funny like that...elephants can wear frilly lace panties, and Dubya still looks like a monkey in a big chair"
"Take four goats and strap one to each foot of a llama. Presto, goat-powered llama!"
"You want to get me to work more, get me a Coke. No? Then deal with inferior garbage, I'm not coding another line and your clients can go to......thanks, I'd love a Coke right about now!"
-
Jun 6th, 2001, 03:32 PM
#8
Monday Morning Lunatic
Replacing characters in Perl is accomplished through regexps 
Code:
$buffer = $ENV{'QUERY_STRING'};
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/~!/ ~!/g;
$FORM{$name} = $value;
}
This code makes an associative array where the key is the value name:
http://server/path/script.pl?val=5%20x
Code:
$val = $FORM{'val'}; # Contains '5 x' (I think)
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 6th, 2001, 03:41 PM
#9
Thread Starter
Member
This is a piece of code in my script:
# Get the form variables
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
$buffer = $ENV{'QUERY_STRING'};
}
else {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}
# Break em up into a format the script can read
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
# Assign shorter variable names
if ($FORM{'sendto'}) { $sendto = $FORM{'sendto'}; }
if ($FORM{'sender'}) { $sender = $FORM{'sender'}; }
if ($FORM{'subject'}) { $subject = $FORM{'subject'}; }
if ($FORM{'message'}) { $message = $FORM{'message'}; }
Now that I've got all the variables, I want to perform
a replace action on the contents of the variables $subject.
I want to replace all "%26" occurences to a "&". So what
code should I place now? (Sorry I'm such a dumb nut)
-
Jun 6th, 2001, 03:44 PM
#10
Monday Morning Lunatic
It's already done it: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
The values are fully parsed and ready for use.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 6th, 2001, 03:52 PM
#11
Thread Starter
Member
So how do you replace these in Perl:
#$% to &
%$# to =
I decided to use #$% and %$# to denote & and = since
they I don't think anyone will use it.
-
Jun 6th, 2001, 03:56 PM
#12
Monday Morning Lunatic
I think I missed something Noone use what?
Code:
$str = '#$%';
$str ~= s/#$%/&/eg;
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 6th, 2001, 04:00 PM
#13
Thread Starter
Member
Forget what I said,
I just want to know the Perl code for replacing the
following characters in the variable $subject:
Replace #$% with &
Replace %$# with =
-
Jun 6th, 2001, 04:03 PM
#14
Monday Morning Lunatic
See above
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 6th, 2001, 04:44 PM
#15
Thread Starter
Member
I'm sorry but I missed it. I don't know much Perl.
Is this the code:
$str ~= s/#$%/&/eg;
$str ~= s/%$#/=/eg;
-
Jun 6th, 2001, 05:00 PM
#16
Monday Morning Lunatic
You got it! Just search for "regular expressions" for more information (on something like google, not here )
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 6th, 2001, 05:18 PM
#17
Thread Starter
Member
I uploaded the script. Here's an excerpt:
Code:
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
# Assign shorter variable names
if ($FORM{'sendto'}) { $sendto = $FORM{'sendto'}; }
if ($FORM{'sender'}) { $sender = $FORM{'sender'}; }
if ($FORM{'subject'}) { $subject = $FORM{'subject'}; }
if ($FORM{'message'}) { $message = $FORM{'message'}; }
$message ~= s/#$%/&/eg;
$message ~= s/%$#/=/eg;
But this is what comes in the error log:
syntax error at /home/public_html/cgi-bin/emailcom.cgi line 37, near "$message ~"
Scalar found where operator expected at /home/public_html/cgi-bin/emailcom.cgi line 38, within string
(Missing semicolon on previous line?)
Execution of /home/public_html/cgi-bin/emailcom.cgi aborted due to compilation errors.
What's the problem?
-
Jun 7th, 2001, 03:18 AM
#18
Monday Morning Lunatic
Blame the fact that I haven't used Perl for months I just realised that some of the characters may be misinterpreted. Try escaping them with \ (like \#\&\")
Also # is the comment character
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 7th, 2001, 03:49 PM
#19
Thread Starter
Member
I tried escaping the characters and it worked!!!
This is the code I used:
$message =~ s/\#\$\%/\&/g;
$message =~ s/\%\$\#/\=/g;
Thanks a lot man! It finally worked!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|