s/mime and net::smtp

TeeJay on 2002-06-28T08:51:54

heres how I did it.. (if I had the time I'd write perl module using xs/swig to provide openssl features)

############################################### #!/usr/bin/perl -w

use strict; use Net::SMTP_auth; # use Net::SMTP if you don't need to login to smtp server

my ($SMTP_TO,$alias) = ("quz\@foo.co.uk"," mr quz"); my $recipient = $SMTP_TO; my $error = undef; if ( $alias =~ /\S/ ) { $SMTP_TO = qq{"$alias" <$SMTP_TO>}; } my $SMTP_HOST = q(smtp.bar.com); my $SMTP_FROM = q(foo@bar.com); my $MAIL_FROM = q(foo@bar.com);

system( qq{openssl smime -encrypt -in mesg.txt -from foo\@bar.com \ -to quz\@foo.co.uk -subject "Encrypted message" \ -out mail.msg quz_cert.pem });

my $smtp = new Net::SMTP_auth($SMTP_HOST, Timeout => 60, Debug => 1); # $smtp->auth('CRAM-MD5', 'username', 'password'); # use if you have to login to smtp server (check auth type first) $smtp->mail($SMTP_FROM); $smtp->to($SMTP_TO);

$smtp->data();

my $body; open(BODY,"mail.msg") or die "couldn't open mail.msg : $!\n"; while (defined ($body = )) { $smtp->datasend($body); } close BODY or warn "couldn't close body text file : $!\n"; $smtp->dataend(); $smtp->quit();

################################################

wicked!