Ah CHU has asked for the wisdom of the Perl Monks concerning the following question:

Dear all ... could you tell me what perl module i should use for sending mail with attachment (wave attachment) ... i'm trying to use "MIME-Lite-2.106" however ... i have to use it in NT 4.0 environment ... how to change the following command ... or actuallly ... can i use this module to do so ... THX
### Cat (Unix only): if (1) { my $path = "cat $gifpath |"; $msg->attach(Subject => "Cat path to pipe, and read that", Path => $path, Type => 'image/gif'); }

Edit 2001-03-09 by mirod: added <code> tags

Replies are listed 'Best First'.
Re: send mail with attachment using SMTP
by ckohl1 (Hermit) on Mar 09, 2001 at 18:06 UTC
    MIME::Lite works for sending mail with attachments from an NT machine:
    my $msg=MIME::Lite->new( From=>$Mail_From, To=>$Mail_To, CC=>$Mail_CC, subject=>$Mail_Subject, Type=>'$Mail_Type', Path=>$Mail_Path, Filename=>$Mail_Filename );
    Chris
Re: send mail with attachment using SMTP
by BlueLines (Hermit) on Mar 09, 2001 at 14:51 UTC
    uh, you set $codepath to "cat $gifpath", which is not likely to be a filename on your machine. Try backticks around cat $gifpath, or just use $gifpath as the arg for MIME::Lite::Path?

    BlueLines

    Disclaimer: This post may contain inaccurate information, be habit forming, cause atomic warfare between peaceful countries, speed up male pattern baldness, interfere with your cable reception, exile you from certain third world countries, ruin your marriage, and generally spoil your day. No batteries included, no strings attached, your mileage may vary.
      oh yes ... i have changed to and then without error ... thx ...
      ### Cat (Unix only): if (1) { my $path = "$gifpath"; $msg->attach(Subject => "Cat path to pipe, and read that", Path => $path,
      the program can run without error ... however ... i can't receive the mail ... maybe my program can't send actually after reading the docs in the module : Change how messages are sent
      ### Do something like this in your 'main': if ($I_DONT_HAVE_SENDMAIL) { MIME::Lite->send('smtp', "smtp.myisp.net", Timeout=>60); } ### Now this will do the right thing: $msg->send; ### will now use Net::SMTP as shown above
      my NT machine hasn't SENDMAIL ... how can i change the way of how i send ? here is my test mail written so far...
      #!/usr/bin/perl -w use strict; use MIME::Lite; use Getopt::Std; #------------------------------ # main #------------------------------ sub main { my %opts; ### Get options: getopts('', \%opts) or die "usage error\n"; my $gifpath = $ARGV[0] || die "missing path to GIF\n"; ### Create message: my $msg = MIME::Lite->new( To => 'ustchu@sinaman.com', Subject => 'GIF test', Type => 'multipart/mixed'); ### Read data: open IN, "<$gifpath" or die "open $gifpath: $!\n"; binmode IN; my @data; local $_ = ''; while (read(IN, $_, 1024)) { push @data, $_; } close IN; ### Direct path: if (1) { my $path = $gifpath; $msg->attach(Subject => "Read path directly", Path => $path, Type => 'image/gif'); } ### Cat (Unix only): if (1) { my $path = "$gifpath"; $msg->attach(Subject => "Cat path to pipe, and read that", Path => $path, Type => 'image/gif'); } ### Array: if (1) { $msg->attach(Subject => "Read data as array", Data => \@data, Type => 'image/gif'); } ### String: if (1) { $msg->attach(Subject => "Read data as string", Data => join('', @data), Type => 'image/gif'); } ### Output: # $msg->print(\*STDOUT); } exit(&main ? 0 : -1); 1; __END__

      Edit: 2001-03-09 by mirod: added <code> tags

Re: send mail with attachment using SMTP
by Desdinova (Friar) on Mar 09, 2001 at 21:24 UTC
    For NT I use the builtin SMTP method it is called be putting
    MIME::Lite->send('smtp','mailrelay');
    Replacing mailrelay with my networks SMTP Host I put this before the I create the MIME object but i dont know if that makes a diiference
sending an attachment without saving to disk
by howard40 (Beadle) on Mar 10, 2001 at 01:03 UTC
    i had to write a script for a company that led me towards MIME::Lite

    The company wanted a form that would allow people to submit/upload resume files; and have the script email those resumes to their personnel department. sendmail was not a requirement, so i used the company's SMTP server (so that it would work on both Win2k/linux)

    on the form, there is a field named 'resume' that is of type 'FILE'. when the user submits the form, i read in the data submitted in the form field 'resume' and put it in the hash key 'resume_data'.

    Then, i break out MIME::Lite and attach the data contained in that hash key to the email message.

    This enables me to send an email with the user's resume attached without ever having to save the resume to a file. ;)

    keep in mind that the following code chunks are ripped out of the larger script... so it might not work as expected if you just cut-n-paste the code
    #$i is an object i declared previously #read in all values (using CGI.pm) my @names = &param(); foreach my $field (@names) { $FORM{$field} = &param($field); } #read in the data uploaded, and save it into a hashkey if ($FORM{'resume'}) { #read in the resume's data my ($data,$size); while( $size = read( $FORM{'resume'}, $data, 1024) ) { $FORM{'resume_data'} .= $data; $FORM{'resume_size'} += $size; } } #---- #resume is the form field of type 'FILE' $FORM{'resume'} =~ m!([^/:\\]*)$!; #get file name/ext my $shortname = $1; #file name (with no slashes or colons +) #---- #create a new message my $msg = MIME::Lite->new( From => "$FORM{'email'}", To => "personnel\@company.com", Subject => "Resume", Type => 'TEXT', Data => "Resume is <attached> to this email as <$shortname>", ) || return $i->error("Cannot create new email message object!"); #attach resume data $msg->attach( Type => 'application/octet-stream', Encoding => 'base64', Data => $FORM{'resume_data'}, Filename => $shortname, ) || return $i->error("Cannot attach your resume to the email!"); #tell MIME::Lite how to send this email MIME::Lite->send('smtp', 'company.com', Timeout=>30) || return $i->error("Unable to set the email 'send' properties!"); #actually send it $msg->send() || return $i->error("Unable to send email with your resume!");
Re: send mail with attachment using SMTP
by lachoy (Parson) on Mar 10, 2001 at 00:51 UTC

    See RE: sending email for an example of code that works on Linux and NT. (Narrowing down operating systems like this reminds me of the Blues Brothers: "What types of music do you have here?" "Oh, both types: Country and Western.")

    Chris
    M-x auto-bs-mode

Re: send mail with attachment using SMTP
by idnopheq (Chaplain) on Mar 11, 2001 at 02:53 UTC
    Use Mail::Sender ... it is on ActiveState's PPM repository
Re: send mail with attachment using SMTP
by davehamptonusa (Initiate) on Mar 10, 2001 at 00:19 UTC
    I've just got a program that doesn't use a lib if you want one. I use it to create .vcf files and attach them to an email to myself so I can directly import the information into my Database instead of having to retype them. Let me know... Oh and I think that Ginger is a scooter - Is that not this site? oops.. sorry.