krystal has asked for the wisdom of the Perl Monks concerning the following question:

I have a cgi script written in perl. It basically generates an encrypted PGP file and shucks it out to an e-mail. The e-mail comes through AOK, I get no errors, but the body (i.e. - the encrypted part) isn't coming through. (I borrowed the PGP part from pgpmail.pl, so that might help.) HEre's most of it (I clipped out extraneous, so don't worry about things like missing subs):
#!/usr/bin/perl $pgpprog = "/usr/local/bin/pgp"; $mailprog = "/usr/sbin/sendmail"; $order_email = "orders\@domain.com"; print "Content-type: text/html\n\n"; sub send_mail { unless (-e $mailprog) { print <<"PrintTag"; <html><body> <h3>Can't find $mailprog</h3> </body></html> PrintTag exit(0); } open (MAIL, "|$mailprog -t") || die "Can't open mail program\n"; print MAIL "To: $order_email\n"; print MAIL "Reply-To: $billemail\n"; print MAIL "From: $billemail\n"; print MAIL "Subject: $email_subj\n\n"; # now open PGP $pgptmp = 'pgptmp'; $pgptmp .= getppid(); $pgptmp .= '.asc'; $ret_val = open (PGP, "|$pgpprog -fea +VERBOSE=0 \"orders@domain.c +om\" > $pgptmp"); if($ret_val < 1) { # print TEST "Cannot open $pgptmp\n"; # close(TEST); die ("Can't open $pgpprog!\n"); } print PGP <<"PrintTag"; An order has recently been placed at $site_address! Billing Information: $billname $billtitle PrintTag print PGP "Quantity: $quantity Item: $name $varname\n"; print PGP "Price Each: \$$price\n"; print PGP "Subtotal: \$"; printf PGP ("%.2f",$subtotal); close (PGP); open(PGPFILE, $pgptmp) || die "Can't open $pgptmp!"; while(<PGPFILE>) { print MAIL; } close (PGPFILE); unlink("$pgptmp"); close (MAIL); } #End of Script

Replies are listed 'Best First'.
Re: Perl and PGPMail
by PodMaster (Abbot) on Apr 02, 2004 at 11:45 UTC
    Hi. When interacting with external programs you have to know how they work. Luckily someone has already worked with sendmail and worked out the details
    E:\>perldoc -q attach Found in C:\Perl\lib\pod\perlfaq9.pod How do I use MIME to make an attachment to a mail message? This answer is extracted directly from the MIME::Lite documentatio +n. Create a multipart message (i.e., one with attachments). use MIME::Lite; ### Create a new multipart message: $msg = MIME::Lite->new( From =>'me@myhost.com', To =>'you@yourhost.com', Cc =>'some@other.com, some@more.com', Subject =>'A message with 2 parts...', Type =>'multipart/mixed' ); ### Add parts (each "attach" has same arguments as "new"): $msg->attach(Type =>'TEXT', Data =>"Here's the GIF file you wanted" ); $msg->attach(Type =>'image/gif', Path =>'aaa000123.gif', Filename =>'logo.gif' ); $text = $msg->as_string; MIME::Lite also includes a method for sending these things. $msg->send; This defaults to using sendmail(1) but can be customized to use SM +TP via Net::SMTP.
    If sendmail doesn't work, try the smtp method. If neither work for you then you need to talk to your system administrator.

    If you need to install MIME::Lite, visit our Tutorials section and read A guide to installing modules (and the docs referenced ).

    Good luck.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Perl and PGPMail
by krystal (Novice) on Apr 02, 2004 at 21:49 UTC
    AS you say, I don't really know how to interface PGP with Perl, thus my posting here. I looked at the references you gave me, looked like they were all written in some other language (I only know Perl, and that is very basic stuff). As for the admin - they won't support any "third party" scripts, so I'm basically screwed 'til I can figure this out. Any one out there want to really dumb down their solution to help me out? Just tell me where I'm going wrong?

      It is hard to say where the script is breaking down. I don't have pgp, so don't know what -fea +VERBOSE does... The best I can do is give you some hints on where to troubleshoot.

      Is the problem that the body is not decrypting properly? or that the body is simply not part of the message when you receive it? Does the body "look" right (obviously if it is encrypted you won't be able to read it, but it should take a fairly obvious shape). How does the body of the message compare to other pgp encrypted email messages that succeed? Is the email missing anything (headers, separators) that is necessary to decrypt it?

      If you print out the message to STDERR (or your error log, or even just back to the browser) does it look like an email message? Does it look like a pgp encrypted email message?

      Do you know for sure that just sending the output of pgp as the body of the email is what you need?

      Answering those questions should narrow it down for you, anyhow. Sorry I can't be of more help.