[Xitami] [Xitami]Attachments to E-mail?

Gregory Hart xitami@lists.xitami.org
Thu, 25 Apr 2002 17:35:43 -0700


I found this at http://www-old.ics.uci.edu/pub/websoft/libwww-perl/archive/1999h1/0053.html. The message is below:

You might want to check out MIME::Entity and company, specifically, the
build, attach, print, and stringify methods.

For example (from MIME::Entity documentation):

my $msg = MIME::Entity->build(
 From     => 'me@myhost.com',
 To       => 'you@yourhost.com',
 Subject  => "Hello, nurse!",
 Data     => [
  'body text line 1',
  'body text line 2',
  'body text line 3'
 ]
);
$msg->attach(
 Path => $my_file_to_attach,
 Type => $my_files_mime_type,
 Encoding => '-SUGGEST'
);
# set up SMTP recipient, sender here
$smtp->datasend($msg->stringify);

# or possibly $msg->print $smtp (I haven't tried this)

So you just use $smtp->datasend once in this case instead of multiple times. Since you have mutliple lines of data, you should be
able to use Data => @body. Hope that works.
-Greg

----- Original Message -----
From:
To: xitami@lists.xitami.org
Sent: Thursday, April 25, 2002 10:19 AM
Subject: [Xitami] [Xitami]Attachments to E-mail?



Question on Attachments to E-mail:

Used Net::SMTP from ActiveState to set up sub to send mail.
This subroutine works correctly, but doesn't provide for
file attachments. Listed SMTP.pm and found entry points
for mail, to, data, and quit, but none for attach.

Do I need to use another module or can Net::SMTP be used?

Also, is there a module available for faxing files?

Listed below is the sub I'm using.

sub send_mail
{ my ($to, $from, $subject, @body, $attach)=@_;
  use Net::SMTP;

  my $relay = "smtp.earthlink.net";
  my $smtp  = Net::SMTP->new($relay);
  die "Open of mail failed" if (! defined $smtp);
  print "Open of mail OK", "<BR>";

  print "Mail beg", "<BR>";
  $smtp->mail($from);
  $smtp->to($to);
  $smtp->data();
  $smtp->datasend("To: $to\n");
  $smtp->datasend("From: $from\n");
  $smtp->datasend("Subject: $subject\n");
  $smtp->datasend("\n");
  foreach(@body)
  {
    $smtp->datasend("$_\n");
  }
  $smtp->dataend("\n");
  $smtp->quit;
}

--- Robert N Meehan 909 784 5908,  214573
--- rmsoftware@earthlink.net
--- EarthLink: It's your Internet.