#!/usr/local/perl5/bin/perl5 # Edit the line above, to point at your local installation of Perl5, # then put this file into your cgi-bin directory, so it can be # accessed by the VXML interpreter. # *********************************************************************** # * BeVocal Sample Code * # * (C) Copyright BeVocal, Inc. 2003, All rights reserved. * # * * # * This Sample Code is provided for your reference purposes, and * # * carries no warranty whatsoever. Use of this code is restricted to * # * use in connection with the BeVocal Cafe developer's program. * # * BeVocal disclaims and excludes any and all warranties of * # * merchantability, title and fitness for a particular purpose. * # * BeVocal does not warrant that the software will satisfy your * # * requirements, or that the software is without defect or error. * # * You are using the software at your own risk. * # *********************************************************************** # include the libraries. use File::Basename; use MIME::Lite; # --------------------------------------------------------------------- # These are here for debugging, in case you need more information # about exactly how the parameters were passed in. # --------------------------------------------------------------------- if (defined($ENV{'REQUEST_METHOD'})) { $method = $ENV{'REQUEST_METHOD'}; } if (defined($ENV{'CONTENT_TYPE'})) { $content_type = $ENV{'CONTENT_TYPE'}; } if (defined($ENV{'CONTENT_LENGTH'})) { $content_length = $ENV{'CONTENT_LENGTH'}; } if (defined($ENV{'QUERY_STRING'})) { $query_string = $ENV{'QUERY_STRING'}; } # --------------------------------------------------------------------- # Read the POSTED data from the STDIN # --------------------------------------------------------------------- read ( STDIN, $buffer, $ENV { 'CONTENT_LENGTH' } ); # --------------------------------------------------------------------- # Split the POSTED data into separate variables # --------------------------------------------------------------------- @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; } # --------------------------------------------------------------------- # Get the attachment from the Name value pair. # NOTE: change the value below (e.g. "recorded" ) to reflect the name # of the item variable which was POSTED to this script # --------------------------------------------------------------------- $attachment = $FORM {"message"}; # --------------------------------------------------------------------- # Construct the email message. The email message is of type # "multipart-mixed" as there are two parts to it. The first part is # a simple text meesage which forms the body of the e-mail.The second # part is the attachment of the recorded data that was POSTED to this # perl script. # NOTE: change the From, To, Subject Fields below to reflect some valid # addresses in your domain. # --------------------------------------------------------------------- $msg = MIME::Lite->new( From =>"me\@myhost.com", To =>"destination\@somecomany.com", Subject =>"Here's an audio email message for you", Type =>"multipart/mixed", ); # --------------------------------------------------------------------- # Construct the body of the email # --------------------------------------------------------------------- $msg->attach( Type => 'TEXT', Data => "The enclosed file , audiofile.wav, was\n sent to you by the Bevocal Cafe.\n Check us out at http://cafe.bevocal.com", ); # --------------------------------------------------------------------- # Attach the recorded wav file as an attachment to this email. # --------------------------------------------------------------------- $msg->attach ( Type => 'audio/wav', Filename=> 'audiofile.wav', Data => "$attachment", Disposition => 'attachment' ); # --------------------------------------------------------------------- # Send the email now. the 'send' method tries to send the email in the # 'best-possible-manner'. By befault it uses sendmail. # --------------------------------------------------------------------- #SPECIFY A MAIL GATEWAY # Note: This IP address specifies the localhost, and this will # work on a lot of machines (it works with my ISP). However, # you might have to change it, to point at a different machine # with an email gateway (i.e. SMTP). #$msg->send; $msg->send('smtp', "127.0.0.1", Timeout=>60); # --------------------------------------------------------------------- # now we have to send some VXML back to be interpreted # --------------------------------------------------------------------- print "Content-type: application/voicexml+xml\n\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "Thank you! Your email message with audio attachment has been sent.\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "Would you like to send another voice email message?\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "Thank you for calling! Goodbye.\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "
\n";