Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

TeeJay (2309)

TeeJay
  (email not shown publicly)
http://www.aarontrevena.co.uk/

Working in Truro
Graduate with BSc (Hons) in Computer Systems and Networks
pm : london.pm, bath.pm, devoncornwall.pm
lug : Devon & Cornwall LUG
CPAN : TEEJAY [cpan.org]
irc : TeeJay
skype : hashbangperl
livejournal : hashbangperl [livejournal.com]
flickr :hashbangperl [flickr.com]

Journal of TeeJay (2309)

Friday June 28, 2002
03:51 AM

s/mime and net::smtp

[ #6036 ]
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 = <BODY>)) {
    $smtp->datasend($body);
}
close BODY or warn "couldn't close body text file : $!\n";
$smtp->dataend();
$smtp->quit();

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

wicked!
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.