Results 1 to 19 of 19

Thread: Ssending mail from VB

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Toronto, Canada
    Posts
    52

    Post 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.

  2. #2
    Lively Member
    Join Date
    Feb 2000
    Posts
    120
    try this
    <A href="mailto:the address @ dot com">
    shachar shaty

  3. #3
    Addicted Member csammis's Avatar
    Join Date
    Mar 2001
    Location
    /dev/null
    Posts
    226
    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!"

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Toronto, Canada
    Posts
    52
    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.

  5. #5
    Addicted Member csammis's Avatar
    Join Date
    Mar 2001
    Location
    /dev/null
    Posts
    226
    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!"

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Toronto, Canada
    Posts
    52
    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???

  7. #7
    Addicted Member csammis's Avatar
    Join Date
    Mar 2001
    Location
    /dev/null
    Posts
    226
    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!"

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  9. #9

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Toronto, Canada
    Posts
    52
    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)

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  11. #11

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Toronto, Canada
    Posts
    52
    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.

  12. #12
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  13. #13

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Toronto, Canada
    Posts
    52
    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 =

  14. #14
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  15. #15

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Toronto, Canada
    Posts
    52
    I'm sorry but I missed it. I don't know much Perl.
    Is this the code:

    $str ~= s/#$%/&/eg;
    $str ~= s/%$#/=/eg;

  16. #16
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  17. #17

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Toronto, Canada
    Posts
    52
    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?

  18. #18
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  19. #19

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Toronto, Canada
    Posts
    52

    Thumbs up

    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
  •  



Click Here to Expand Forum to Full Width