Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mime::Lite

Status
Not open for further replies.

BobWeston

Programmer
Mar 18, 2002
13
US
Hi All!
I'm fairly new to Linux (getting better everyday) and new to Perl (this will be my first experience).

On our Linux box, we have a shell script that makes some changes to a file and emails the file to one or more users. Currently, the email is sent through MUTT, but we've only been able to send out a plain text body. Our internal client has asked that the emails come out with nicely formatted HTML and images using the same theme as their intranet site.

After looking around, it seems Mime::Lite would be an easy enough way to do this. I found the script I'm using on so I think I'm fairly good to go in that respect. Now I just need to figure out how to call the Perl script from the shell script and pass the to: variables as well as the path to the attachment.

This is where I'm stuck. I have no idea how to call a Perl script from the shell script. Help!?

Thanks,

Bob
 
Siberian,
Thanks for taking the time to reply. I already have code for sending attachments, as mentioned in my original post.

What I'm trying to figure out how to do is call the said script from a shell script and pass a couple variables: the To: address and the path to the file attachment.

If you or anyone else can help me with that aspect, I would be grateful.

Thanks,

Bob
 
If you want to send switched arguments try Getopt::Simple (At cpan).

If you just want to pass args like this

script.pl arg1 arg2 arg3

Use the @ARGV array where each position is an argument.

 
Siberian,
Ok, I've created a perl script called sendemail.pl as the the following:

use strict;
use warnings;

use MIME::Lite;

my $from_address = 'account@myhost.com';
my $to_address = 'myemail@myhost.com';
my $subject = 'Mime Test';
my $mime_type = 'TEXT';
my $message_body = "Hello World!\n";

my $mime_msg = MIME::Lite->new(
From => $from_address,
To => $to_address,
Subject => $subject,
Type => $mime_type,
Data =>$message_body
)
or die "Error Creating MIME Body" $!\n";

$mime_msg->send;

When I execute the code, I get the following errors:

/tmp/sendemail.pl: line 1: use: command not found
/tmp/sendemail.pl: line 2: use: command not found
/tmp/sendemail.pl: line 4: use: command not found
/tmp/sendemail.pl: line 6: my: command not found
/tmp/sendemail.pl: line 7: my: command not found
/tmp/sendemail.pl: line 8: my: command not found
/tmp/sendemail.pl: line 9: my: command not found
/tmp/sendemail.pl: line 10: my: command not found
/tmp/sendemail.pl: line 12: syntax error near unexpected token `('
/tmp/sendemail.pl: line 12: `my $mime_msg = MIME::Lite->new('

I've taken this example from the article found on
I've installed MIME::Lite and am trying to send this out through sendmail.

Being new to Perl, I'm not sure what to do next.

Any help would be appreciated.

Thanks,

Bob
 
You need the path to perl line at the beginning

Code:
#!/usr/bin/perl
(or wherever your perl is)

 
Thanks Siberian! That will be the first and last time I make that mistake!!!

Ok, made that change and a few other tweaks and it worked like a champ! Now to try sending HTML :)

Thanks for your help!

Bob

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top