Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I wish to send a text file as attachment to the my mailid from my centos box using perl. I tried but could no succeed. Please help in writing the code in perl to attach a text file
I wish to send a text file as attachment to the my mailid from my centos box using perl. I tried but could no succeed. Please help in writing the code in perl to attach a text file
Thanks,
Prakash.
"Help in writing the code"? Sure, post what you've written so far, along with the error(s) you're getting, and we can help you. Otherwise, look up mime::lite or email::mime on CPAN.
If you're looking for someone to write code for you, that's called a "consultant" or "programmer", and they typically get paid to do it.
## Mail Header
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
## Mail Body
print MAIL " Hai this is a test message. \n";
As mentioned, read up on Mime::Lite at search.cpan.org
Here's one I wrote
Code:
# Set the fields required by Mailer...
$contact_email = $cfg::params{'USER_EMAIL'};
$sender = "$prog_full_name";
$subject = " Asset Mgr Report for : $table_name";
$body_text = "This is an automated message:\n\n".
"CSV report of active rows in $table_name\n\n".
"Regards,\n$prog_full_name at $hostname\n\n";
# ... and send it
# Header
$msg = MIME::Lite->new(
From => $sender,
To => $contact_email,
Subject => $subject,
Type =>'multipart/mixed',
Debug => 1
);
# Body Content
$msg->attach(
Type => 'TEXT',
Data => $body_text
);
# Attachment
$msg->attach(
Type => 'text/plain',
Path => "$rpt_file",
Filename => "${rpt_filename}.${rpt_filext}",
Disposition => 'attachment'
);
You need to read those links I put in your other thread. They'll teach you how to use Perl.
If you want Perl to use a non-Core module, you have to specify it to be used explicitly, a bit like you would in C.
In this case
$contact_email = "prakash.akumalla@xxx.com";
$sender = "root@localhost.com";
$subject = " Asset Mgr Report for : $table_name";
$body_text = "This is an automated message:\n\n".
"CSV report of active rows in $table_name\n\n".
"Regards,\n$prog_full_name at $hostname\n\n";
# ... and send it
# Header
$msg = MIME::Lite->new(
From => $sender,
To => $contact_email,
Subject => $subject,
Type =>'multipart/mixed',
Debug => 1
);
# Body Content
$msg->attach(
Type => 'TEXT',
Data => $body_text
);
# Attachment
$msg->attach(
Type => 'text/plain',
Path => "/root/localhost.csv",
Filename => "${rpt_filename}.${rpt_filext}",
Disposition => 'attachment'
);
It did not work. Apart from the attachment, mail is also not been sent.
$msg = MIME::Lite->new (
From => 'root@localhost.com',
To => 'prakash.akumalla@xxx.com',
Subject => 'Test Mail',
Type =>'multipart/mixed'
) or die "Error creating multipart container: $!\n";
$Mail_msg = "This is the test mail";
$attachment = "/root/localhost.csv";
$datafilename = "localhost.csv";
### Add the text message part
$msg->attach (
Type => 'TEXT',
Data => $Mail_msg
) or die "Error adding the text message part: $!\n";
### Add the text file
$msg->attach (
Encoding => 'base64',
Type => "text/csv",
Path => $attachment,
Filename => $datafilename,
Disposition => 'attachment'
) or die "Error adding $datafile: $!\n";
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.