CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Post deleted by Jon Kernighan

 



Jon Kernighan
New User

Feb 6, 2010, 7:07 AM

Post #1 of 3 (638 views)
Post deleted by Jon Kernighan

 


7stud
Enthusiast

Feb 6, 2010, 10:25 PM

Post #2 of 3 (620 views)
Re: [Jon Kernighan] ATT00132.txt spurious attachment sending attachments through smtp [In reply to] Can't Post

Search 'code tags' on google. Read the first 10 hits. Then come back and post what you have learned.


Jon Kernighan
New User

Feb 7, 2010, 1:22 AM

Post #3 of 3 (618 views)
Re: [7stud] ATT00132.txt spurious attachment sending attachments through smtp [In reply to] Can't Post


Code
#!/usr/bin/perl	 

use strict;
use warnings;
use Net::SMTP;
use MIME::Base64;

my $smtp_server = 'localhost';
my $PDF = 'application/x-pdf';
my $TXT = 'text/plain';
my $MP3 = 'audio/mp3';
my $BIN = 'application/octet-streamm';
my $to = 'jon@passby.co.uk';
my $from = 'somebody@here.com';
my $attachment = "/home/polypsy1/public_html/index.php";
my $subject = 'em.pl EMail test script';

my $content;
{
local $/ = undef;
if (open IN, $attachment)
{
binmode IN;
$content = <IN>;
close IN;
}
else
{
$content='What a load of rubbish!';
}
}

my $encode = encode_base64($content);

my $boundary = '<---------Jon_';
my @chrs = ('0'..'9', 'A'..'Z','a'..'z');
foreach (0..16)
{
$boundary .= $chrs[rand(scalar @chrs)];
}
$boundary .= "------------->";


my $msg = <<EOD;
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="$boundary"
From: $from
Reply-To: $to
X-Mailer: fubar.pl
To: $from
Date: Sat, 6 Feb 2010 00:00:05 -0000
Subject: $subject

This is a multi-part message in MIME format.

--$boundary
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Attached is the same file in 3 formats.
--$boundary
Content-Type: $PDF; name=$attachment
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=fred.pdf

$encode
--$boundary
Content-Type: $TXT; name=$attachment
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=fred.txt

$encode
--$boundary
Content-Type: $BIN; name=$attachment
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=fred.bin

$encode
--$boundary

EOD

my $smtp = Net::SMTP->new($smtp_server, Timeout => 60) or die "Cannot connect to smtp server";
$smtp->mail($ENV{USER});
$smtp->to($to);
$smtp->data();
$smtp->datasend($msg);
$smtp->dataend();
$smtp->quit;


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives