0

I have used this script to send the text file, the email go out with attachment but when I open the attached file it's blank. any idea why? did I miss anything. thx

#!/usr/bin/perl -wl
my $msg = MIME::Lite->new(
    From    => 'xxx.net',
    To      => 'xxx.com',
    Subject => 'Report',
    Type    => 'multipart/mixed',
)or die "Error creating multipart container: $!\n";
$msg->attach(
    Type     => 'TEXT',
    Data     => " Please check the attached file.",
)or die "Error adding the text message part: $!\n";
$msg->attach (
   Type => 'text/plain',
   Path => '/myfile/file1',
   Filename => 'result.txt',
   Disposition => 'attachment'
)or die "Error adding the attached file part: $!\n" ;
$msg->send;
Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
dan
  • 185
  • 1
  • 5
  • 11
  • when posting code, indent it 4 spaces (or use the `{}` button in the editor) so it displays correctly. – Jim Garrison May 25 '11 at 20:36
  • What do you see if you look at the message source at the receiving client? – Jim Garrison May 25 '11 at 20:37
  • thank you all!! I have added a full path on "Path => '/myfile/file1' replace Path => '/myfile/file1/result.txt', and the file attached. – dan May 25 '11 at 20:58
  • Make sure that the file isn't being "cleaned up" by the client's mail server. Some mail servers won't allow certain attachment types. – David W. May 25 '11 at 21:02
  • 1
    Might have something to do with `Path` not ending with a slash. I seem to recall some modules are picky about that. E.g. it should be `Path => '/myfile/file1/'` – TLP May 25 '11 at 21:10

1 Answers1

3

You're a little confused about the arguments to attach. From the fine manual:

Filename
Optional. The name of the attachment. You can use this to supply a recommended filename for the end-user who is saving the attachment to disk. You only need this if the filename at the end of the "Path" is inadequate, or if you're using "Data" instead of "Path". You should not put path information in here (e.g., no "/" or "\" or ":" characters should be used).

[...]

Path
Alternative to "Data" or "FH". Path to a file containing the data... actually, it can be any open()able expression. If it looks like a path, the last element will automatically be treated as the filename. See "ReadNow" also.

The Path is the full path to the file that you want to attach, the Filename is the name that you want to receiver to see for that file.

I think you want this:

$msg->attach (
   Type => 'text/plain',
   Path => '/myfile/file1/result.txt',
   Filename => 'result.txt',
   Disposition => 'attachment'
) or die "Error adding the attached file part: $!\n" ;
mu is too short
  • 426,620
  • 70
  • 833
  • 800