LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-18-2007, 04:00 AM   #1
tanveer
Member
 
Registered: Feb 2004
Location: e@rth
Distribution: RHEL-3/4/5,Gloria,opensolaris
Posts: 525

Rep: Reputation: 39
send mail with inline images along with html in perl


Hi,

I am willing to send an auto reply with Perl and procmail for auto reply.

My procmail file is as follows:
Code:
PMDIR=$HOME/procmail
#The log of this procmail rc will store
#in user'home directory/procmail/log file
LOGFILE=$PMDIR/log
VERBOSE=no
 LOG=" "
 SHELL=/bin/sh    # for other shells, this might need adjustment
              :0 Whc: vacation.lock
              * !^FROM_DAEMON
#This portion will not generate any email auto reply to DAEMON
              * !^X-Loop: user@xxx.com
# This will not generate any email auto reply to
              | formail -trD 8192 vacation.cache

               :0 ehc         # if the name was not in the cache
                * ? test  ! -f flag
#this portion will check if the flag file exist or not if not exist then it will work
               | (formail -trI"Precedence: junk" \
                     -A"X-Loop: user@xxx.com";  \
                ) | /home/user/scripts/script.pl
If I use this script then it sends the mail with the htm file as body but at the place of image it shows a cross like missing file.

Code:
 script.pl 
#!/usr/bin/perl
use MIME::Lite;
use Net::SMTP;

my $toline="";
my $subject=""; 
while (<>)
{
	$toline=$_ if /^To:/;
	$subject=$_ if /^Subject:/;
}

my @ar=split(/ /,$toline);
my $ToAddress=$ar[1];

$subject =~ s/^Subject://;

my $to_address = $ToAddress;

my $mail_host = 'current machine IP';


### Create the multipart container

$msg = MIME::Lite->new (

  From => $from_address,

  To => $to_address,

  Subject => $subject,

  Type =>'multipart/mixed'

) or die "Error creating multipart container: $!\n";


$my_file_html="/home/user/contents/test.htm" if $subject =~ /test/i;


$msg->attach (

   Type => 'text/html',
   Path => $my_file_html,
   Filename => $my_file_html,

) or die "Error adding $my_file_html: $!\n";

### Send the Message

MIME::Lite->send('smtp', $mail_host, Timeout=>60);

$msg->send;
Now in test.htm there are one gif files which doesn't show so I added this:
Code:
$msg->attach(
    Type       => 'image/gif',
    Id         => 'myimage.gif',
    Path       => '/home/user/contents/test_files/image003.gif',
);
And also changed in the test.htm file as <img src="cid:myimage">. Now it sends both the htm file and image file as attachments. Nothing is then in the mail body.

The interesting part is if use something like this then it works:

Code:
...
......
$msg->attach (

   Type => 'text/html',

   Data => qq{
            <body>
                Here's <i>my</i> image:
                <img src="cid:myimage.gif">
            </body>
        },

) or die "Error adding $my_file_html: $!\n";

$msg->attach(
    Type       => 'image/gif',
    Id         => 'myimage.gif',
    Path       => '/home/user/contents/EDGE_M_files/image003.gif',
);

....
......
But if gives the htm file location then it sends as attachments as I cant write a whole htm file in the script.
Any idea on this.

thanks for your time.

Last edited by tanveer; 11-18-2007 at 04:01 AM.
 
Old 12-11-2007, 10:51 PM   #2
tanveer
Member
 
Registered: Feb 2004
Location: e@rth
Distribution: RHEL-3/4/5,Gloria,opensolaris
Posts: 525

Original Poster
Rep: Reputation: 39
I cant believe no one ever done this before.
I followed the script of this link & it sends html mail with inline images too. http://www.gerd-tentler.de/tools/mim...erl/index.html

But when I put this in my .procmailrc of users home folder for auto generated reply it gives an error log like this:

Code:
From user@test.com  Tue Dec 11 12:47:52 2007
 Subject: Redhat
  Folder: /var/spool/mail/user
2746
Can't locate MIMEMAIL.pm in @INC (@INC contains: /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 .) at /home/user/scripts/mailtest.pl line 3.
Any help on this please.
FYI,

I can run the same script if I execute it from command shell. But when try to run from .procmailrc file it gives the above error.

Last edited by tanveer; 12-12-2007 at 12:41 AM.
 
Old 12-14-2007, 05:23 AM   #3
tanveer
Member
 
Registered: Feb 2004
Location: e@rth
Distribution: RHEL-3/4/5,Gloria,opensolaris
Posts: 525

Original Poster
Rep: Reputation: 39
finally sorted it out. Very simple thing but cost me lot pain. Should be very easy for people with little knowledge on perl as I don't have that so.... . Ne One interested, let me know.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[Evolution] Save images from html-mail (Dilbert) senorsnor Linux - Software 7 12-29-2006 10:24 AM
Send HTML mail via command line interface xlash Linux - General 2 11-02-2005 01:02 PM
Send Mail with Perl Cool_Hand_Luke Programming 2 03-14-2005 09:59 AM
Java Mail fails to send a HTML mail eantoranz Programming 1 11-10-2004 01:47 PM
Perl - MIME/HTML mail Shak Programming 3 03-09-2003 07:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:08 PM.

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