LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-28-2010, 01:39 PM   #1
++nick++
Member
 
Registered: Dec 2008
Location: Bellevue,WA
Distribution: RHEL 5 , Fedora ,Sabayon,Solaris,Vmware,AWS
Posts: 107

Rep: Reputation: 18
Mail attachment using perl


Hello All,

My script collects information and writes it to a xls file and should mail it across.

I tested the first part of the script which writes the excel file , it does write the excel file fairly with expected data using Spreadsheet::WriteExcel module

Second part uses MIME::Lite , All I get is a mail with intended subject intact but without the attachment . Following is the code , I have googled and tried out many options , didn't go any further apart from receiving a mail without attachment.

use MIME::Lite;

$msg = MIME::Lite->new(
From => 'xx',
To => 'xx',
Subject => 'using module'
);

$msg->attach(
Type => 'application/xls',
Encoding => 'base64',
);
$msg->attach(
Path => '/tmp/hello.xls',
Filename => 'hello.xls',
Disposition => 'attachment'
);

$msg->send();

I am using RHEL 4 , Perl 5.8

Kindly advise me of what might be going wrong . Thanks in Advance.

Last edited by ++nick++; 02-28-2010 at 01:41 PM.
 
Old 02-28-2010, 01:53 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by ++nick++ View Post
Hello All,

My script collects information and writes it to a xls file and should mail it across.

I tested the first part of the script which writes the excel file , it does write the excel file fairly with expected data using Spreadsheet::WriteExcel module

Second part uses MIME::Lite , All I get is a mail with intended subject intact but without the attachment . Following is the code , I have googled and tried out many options , didn't go any further apart from receiving a mail without attachment.

use MIME::Lite;

$msg = MIME::Lite->new(
From => 'xx',
To => 'xx',
Subject => 'using module'
);

$msg->attach(
Type => 'application/xls',
Encoding => 'base64',
);
$msg->attach(
Path => '/tmp/hello.xls',
Filename => 'hello.xls',
Disposition => 'attachment'
);

$msg->send();

I am using RHEL 4 , Perl 5.8

Kindly advise me of what might be going wrong . Thanks in Advance.
First forget about Excel and try to send a plain text attachment.

...

I haven't read the documentation, but are you sure you have to call the 'attach' method twice ? And are you sure the return value of the 'attach' method shouldn't be checked for errors ?

Last edited by Sergei Steshenko; 03-01-2010 at 05:25 AM.
 
Old 03-01-2010, 04:34 AM   #3
++nick++
Member
 
Registered: Dec 2008
Location: Bellevue,WA
Distribution: RHEL 5 , Fedora ,Sabayon,Solaris,Vmware,AWS
Posts: 107

Original Poster
Rep: Reputation: 18
Thanks for the reply,

I tried to mail a plain text file , it didnt work either , all I received is a mail without attachment , below is the code,

use MIME::Lite;

$mail = MIME::Lite->new(
From => 'xx',
To => 'xx',
Subject => 'mailing a text attachment using mime lite',
);

$mail -> attach(
Type => 'text/html',
Path => '<absolute path>',
Filename => 'file1',
Disposition => 'inline',
);

$mail -> send();

#END

Kindly advice
 
Old 03-01-2010, 05:14 AM   #4
karthi_27
LQ Newbie
 
Registered: Mar 2010
Posts: 6

Rep: Reputation: 0
Thumbs up Try this

Hello nick,

Try the following code.

Code:
use strict;
use warnings;

use MIME::Lite;

my $msg = MIME::Lite->new(
    From    => 'xxx',
    To      => 'xxx',
    Subject => ' Test message',
    Type    => 'multipart/mixed',
);

$msg->attach(
    Type     => 'text',
    Data     => "Here is the file",
);

$msg->attach(
    Type     => 'text',
    Path     => '/home/user/Documents/Assignment1',
    Filename => 'Assignment1',
);

$msg->send;
Always mention the type of the data you going the send.

Thanks.

Last edited by karthi_27; 03-01-2010 at 05:15 AM.
 
Old 03-01-2010, 05:15 AM   #5
++nick++
Member
 
Registered: Dec 2008
Location: Bellevue,WA
Distribution: RHEL 5 , Fedora ,Sabayon,Solaris,Vmware,AWS
Posts: 107

Original Poster
Rep: Reputation: 18
Hello All,

Adding a line(Type => 'multipart/mixed',) to the code made all the difference , fine the code below ,

use MIME::Lite;

$mail = MIME::Lite->new(
From => 'ramkar',
To => 'ramkar',
Subject => 'mailing a text attachment using mime lite',
Type => 'multipart/mixed',
);

$mail -> attach(
Type => 'text/html',
Path => '/ms/user/r/ramkar/file1',
Filename => 'file1',
Disposition => 'attachment',
);

$mail -> send();

#END

Thanks All.
 
Old 03-01-2010, 05:17 AM   #6
++nick++
Member
 
Registered: Dec 2008
Location: Bellevue,WA
Distribution: RHEL 5 , Fedora ,Sabayon,Solaris,Vmware,AWS
Posts: 107

Original Poster
Rep: Reputation: 18
Hi,

Thanks karthi , I saw your post only after posting mine in which i expressed the need for mentioning Type , thanks anyways

Cheers
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl: how to save an e-mail attachment on disk keeping the "&" character (no "%26"!!) d1s4st3r Programming 5 09-29-2010 09:30 PM
mail attachment tostay2003 Linux - Software 6 10-01-2006 07:07 PM
howto send a mail with attachment via perl script ? cccc Programming 24 03-05-2004 07:49 PM
mail -a would not work to send e-mail attachment saavik Linux - Networking 3 12-18-2003 09:33 AM
mail with attachment joseph Linux - Networking 1 08-31-2003 10:01 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration