Email with text file attachment

Email with text file attachment

am 01.12.2007 01:18:50 von Yaw Lim

What is the easiest way to send an email with a text file attachment
(without MIME::LITE, etc)?

/Why Tea

Re: Email with text file attachment

am 01.12.2007 01:39:26 von jurgenex

Why Tea wrote:
> What is the easiest way to send an email with a text file attachment

Your Question is Asked Frequently, please see "perldoc -q attachment".

> (without MIME::LITE, etc)?

Oh, in that case I would guess by re-implementing significant parts of
MIME::LITE from scratch in your program.

jue

Re: Email with text file attachment

am 01.12.2007 05:12:43 von Yaw Lim

> > (without MIME::LITE, etc)?
>
> Oh, in that case I would guess by re-implementing significant parts of
> MIME::LITE from scratch in your program.

Oh, not really. I have seen bits and pieces about using sendmail or
similar. I'm only after a minimal way of sending an email with a text
attachment without any additional package.

Re: Email with text file attachment

am 01.12.2007 05:30:41 von Ron Bergin

On Nov 30, 8:12 pm, Why Tea wrote:
> > > (without MIME::LITE, etc)?
>
> > Oh, in that case I would guess by re-implementing significant parts of
> > MIME::LITE from scratch in your program.
>
> Oh, not really. I have seen bits and pieces about using sendmail or
> similar. I'm only after a minimal way of sending an email with a text
> attachment without any additional package.

This is not the method I'd use, because I'd be using MIME::Lite, but
you could do a system call to uuencode (to encode your file
attachment) and pass it to the mail command.

man uuencode
man mail

Re: Email with text file attachment

am 01.12.2007 12:57:49 von Martijn Lievaart

On Fri, 30 Nov 2007 20:30:41 -0800, Ron Bergin wrote:

> This is not the method I'd use, because I'd be using MIME::Lite, but you
> could do a system call to uuencode (to encode your file attachment) and
> pass it to the mail command.

I've used this method often and it works like a charm.

M4

Re: Email with text file attachment

am 01.12.2007 18:25:54 von Ron Bergin

On Dec 1, 3:57 am, Martijn Lievaart wrote:
> On Fri, 30 Nov 2007 20:30:41 -0800, Ron Bergin wrote:
> > This is not the method I'd use, because I'd be using MIME::Lite, but you
> > could do a system call to uuencode (to encode your file attachment) and
> > pass it to the mail command.
>
> I've used this method often and it works like a charm.
>
> M4

Yes, it does work, but it's not as flexible and it unnecessarily
spawns additional processes. This method of sending an email is not
"not very Perlish"; it's most often done in shell scripts. So, do you
want to write a shell script or perl script?

Re: Email with text file attachment

am 01.12.2007 21:50:42 von Martijn Lievaart

On Sat, 01 Dec 2007 09:25:54 -0800, Ron Bergin wrote:

> On Dec 1, 3:57 am, Martijn Lievaart wrote:
>> On Fri, 30 Nov 2007 20:30:41 -0800, Ron Bergin wrote:
>> > This is not the method I'd use, because I'd be using MIME::Lite, but
>> > you could do a system call to uuencode (to encode your file
>> > attachment) and pass it to the mail command.
>>
>> I've used this method often and it works like a charm.
>>
>> M4
>
> Yes, it does work, but it's not as flexible and it unnecessarily spawns
> additional processes. This method of sending an email is not "not very
> Perlish"; it's most often done in shell scripts. So, do you want to
> write a shell script or perl script?

Sometimes I want to write a script that works without installing
additional modules. In medical environments it is simpler to get one
script validated than a script plus installing new modules.

Besides, Perl is a very good glue language, often better suited than the
shell. So yes, maybe I just want to write a shell script and do it in
Perl.

M4

Re: Email with text file attachment

am 02.12.2007 05:49:58 von Yaw Lim

> > Yes, it does work, but it's not as flexible and it unnecessarily spawns
> > additional processes. This method of sending an email is not "not very
> > Perlish"; it's most often done in shell scripts. So, do you want to
> > write a shell script or perl script?
>
> Sometimes I want to write a script that works without installing
> additional modules. In medical environments it is simpler to get one
> script validated than a script plus installing new modules.

This is exactly my point although I'm not in the medical field.

> Besides, Perl is a very good glue language, often better suited than the
> shell. So yes, maybe I just want to write a shell script and do it in
> Perl.

Can anyone share a bare minimum plain vanilla Perl script that glues a
few Unix commands to send an email with a text file?

Re: Email with text file attachment

am 02.12.2007 09:05:53 von Ben Morrow

Quoth Why Tea :
>
> Can anyone share a bare minimum plain vanilla Perl script that glues a
> few Unix commands to send an email with a text file?

#!/usr/bin/perl

open my $MAIL, '-|',
mutt =>
-a => '/a/text/file',
-s => 'Test email',
'foo@bar.com'
or die "can't fork mutt: $!";

print $MAIL "Hello world!\n";
close $MAIL or die "sending mail failed: $!";

__END__

Ben