With a little change, the CSV came through as an attachment.
use strict;
use warnings;
use Net::SMTP;
my $msg = "foo";
my $subj = "my test subject";
my $csvfile = "opnet_ace_cap_agent_audit_$subj.csv";
my $boundary = 'frontier';
my $hostname = "myhost";
my @to = ( "user\@localhost" );
my @csv = (
"one line of csv",
"another line of csv",
);
my $smtp = Net::SMTP->new('smtp.somecorp.com', Timeout => 60);
$smtp->mail( "root\@$hostname.somecorp.com" );
$smtp->to( @to);
$smtp->data();
foreach my $dst ( @to ) { $smtp->datasend( "To: $dst\n" ) }
# @to is a global (ducks for cover)
$smtp->datasend("Subject: Opnet: Ace Capture Agent Audit: $subj\n");
$smtp->datasend("MIME-Version: 1.0\n");
$smtp->datasend("Content-type: multipart/mixed; \n\tboundary=\"$bounda
+ry\"\n");
$smtp->datasend("\n");
$smtp->datasend("--$boundary\n");
$smtp->datasend("Content-type: text/plain\n");
$smtp->datasend("Content-Disposition: quoted-printable\n");
$smtp->datasend("\n$msg\n");
$smtp->datasend("--$boundary\n");
$smtp->datasend("Content-Type: application/text; name=\"$csvfile\"\n")
+;
$smtp->datasend("Content-Disposition: attachment; filename=\"$csvfile\
+"\n");
$smtp->datasend("\n");
$smtp->datasend(\@csv); # Global array (ducks for cover again).
$smtp->datasend("--$boundary--\n");
$smtp->dataend();
$smtp->quit;
update: it's not very good CSV content, but it did come through as an attachment. |