Reputation: 2153
how can i add image and hyperlink to an email in perl using sendmail?
this is the body that i want in the $message (variable):
your file : filename.jpg
(add image here inline)
has been proccess you can find it at: add link here `
here is my code:
sub sendEmail
{
my ($to, $from, $subject, $message) = @_;
my $sendmail = '/usr/lib/sendmail';
open(MAIL, "|$sendmail -oi -t");
print MAIL "From: $from\n";
print MAIL "To: $to\n";
print MAIL "Subject: $subject\n\n";
print MAIL "$message\n";
close(MAIL);
}
sendEmail($receiver, 'admin, 'your file has been Synchronized', $message);
Upvotes: 0
Views: 4608
Reputation: 107040
If all you want to do is provide a simple link embedded in your text message, you may simply decide it's not worth the pain and effort involved.
However, here's a quick synopsis:
use MIME::Lite;
[...]
# First Create your message...
my $message = MIME::Lite->new(
From => $from_email,
To => $to_email,
Cc => join(", " => @cc_addresses),
Subject => $subject,
Type => 'multipart/related',
);
# Now, we have to attach the message in HTML. First the HTML
my $html_message = <<"EOM";
<body>
<p> Your File: <img src='cid:my_image.gif'/> has been processed
and can be found <a href="$file_url">here</a>.</p>
</body>
EOM;
# Now define the attachment
$message->attach (
Type => 'text/html',
Data => $html_message,
);
# Let's not forget to attach the image too!
$message->attach (
Type => 'image/gif',
Id => 'my_image.gif',
Path => $file_name,
);
$message->send
or die qq(Message wasn't sent: $!\n);
Take a look at the MIME Primer included with the MIME::Lite
module. As you can see, simply adding a single email link and a single image requires a lot more work than most of us want to do.
Upvotes: 2
Reputation: 3460
You probably need to use a Perl module that allows you to create MIME attachments. There should be a bunch on CPAN, for example, MIME::Lite. See a discussion at:
http://www.revsys.com/writings/perl/sending-email-with-perl.html
Upvotes: 2