email encrypted form

Anthony E. Greene
Fri Nov 30 08:23:01 2001

Hash: SHA1

On Thu, 29 Nov 2001, Brandon Rasler wrote:

>I am trying to email an encrypted form using this script.
>open(MAIL, "|/home/menno/bin/gpg --homedir /home/menno/.gnupg -a -r
>'0x8ED34D6B' -e --no-secmem-warning -|/usr/sbin/sendmail -t
>user\") || die ("can't open sendmail");
>print MAIL "You Said: $FORM{ 'line' }\n";
>It is working fine but I have several forms and I would like to add headders
>so I know which form it is from.
>How would I add headders before running gpg?

You could write the headers to a temp file, then append the GPG data and
call sendmail to send the whole thing. 

You could put the whole plaintext message into a single string variable,
then use backticks to pipe the data to gpg and capture the output into
another string. Then open a pipe to sendmail and send the headers, then
the encrypted string.

$scriptname = `basename $0`;
$recipient = '"Full Name" <user@domain.tld>';
$keyid = '0xNNNNNNNN';
$plainmessage = "You said blah, blah, blah.\n";
$ecnryptedmessage = `echo "$plainmessage" |/home/menno/bin/gpg \
 --homedir /home/menno/.gnupg -a -r $keyid -e --no-secmem-warning`;
open(MAIL,"|/usr/sbin/sendmail -oi -t");
print MAIL "From: $scriptname <nobody>\n";
print MAIL "To: $recipient\n";
print MAIL "Subject: Web form data\n\n";
print MAIL "$encryptedmessage\n";

Or you could just specify an appropriate subject on the command line:

$scriptname = `basename $0`;
$recipient = '';
$keyid = '0xNNNNNNNN';
$subject = "Web form data ($scriptname)";
$gpgcmd = "/path/to/gpg --homedir /path/to/.gnupg -a -r $keyid\ 
 -e --no-secmem-warning";
$mailcmd = "/bin/mail -s \"$subject\" $recipient ";
open(MAIL,"| $gpgcmd | $mailcmd");
print MAIL "You said blah, blah, blah.\n";

>I tried the following with no luck.
>open(MAIL, "|/usr/sbin/sendmail -t user\") || die ("can't open
>print MAIL "From: Secure_Form_1\n";
>print MAIL "To: user\\n";
>print MAIL "Subject: Results from Secure Form 1\n";
>print MAIL "Content-type:text/plain\n";
>open(OUT, "|/home/menno/bin/gpg --homedir /home/menno/.gnupg -a -r
>'0x8ED34D6B' -e --no-secmem-warning -");
>print OUT "You Said: $FORM{ 'line' }\n";

You specified the email recipient on the sendmail command line and in the
"To:" header. Also, you cannot redirect the output of gpg into the
existing pipe to sendmail. The closest thing you can do to this is to
write a tempfile and pipe the tempfile to sendmail.

- -- 
Anthony E. Greene <> <>
PGP Key: 0x6C94239D/7B3D BD7D 7D91 1B44 BA26 C484 A42A 60DD 6C94 239D
Chat: AOL/Yahoo: TonyG05
Linux. The choice of a GNU generation <>

Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Anthony E. Greene <> 0x6C94239D