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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Advanced:
encoding txt file



Jun 16, 2010, 12:24 PM

Post #1 of 3 (2309 views)
encoding txt file Can't Post


I am trying to encode .txt file to send it as an email attachment.

The code works for all kind of files such as pdf, doc, jpg, but it does not proper encode txt file.

I have tried to replace 'Multipart/Mixed' with 'text/x-setext'. That doesn't help.

As the result I get
where the second line is not supposed to be there.

Any ideas?

use strict; 
use warnings;
use net::smtp;
use MIME::Base64;

my $smtp_server = ' goes here';
my $user = 'mail user id goes here';
my $pass = 'mail password goes here';
my $to = '';
my $from = '';
my $attachment = "ncoacodes.pdf";
my $ct = 'Multipart/Mixed';
my $subject = 'automated email test of attached pdf';

my $content;
local $/ = undef;
open IN, $attachment or die "Error opening $attachment: $!";
binmode IN;
$content = <IN>;
close IN;

my $encode = encode_base64($content);

my $boundary = '<--------- BFC:';
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
To: $to
Date: Wed, 01 Jun 2009 13:12:05 -0500
Subject: $subject

This is a multi-part message in MIME format.

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

Attached is a test file.

Content-Type: $ct; name=$attachment
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=$attachment


my $smtp = Net::SMTP->new($smtp_server, Timeout => 60) or die "Cannot connect to smtp server";


Jun 16, 2010, 11:45 PM

Post #2 of 3 (2294 views)
Re: [mybend] encoding txt file [In reply to] Can't Post

For multipart Mails I use
with the as_string method.
And the string will be sended by Net::SMTP because MIME::Lite has no correct error handling in smtp communication.


Jun 17, 2010, 4:33 AM

Post #3 of 3 (2289 views)
Re: [Bianca] encoding txt file [In reply to] Can't Post

I don't have an option of using MIME::Lite in this case unfortunately... :(


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

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