<html>
<body>
At 2003/06/06 10:55 AM, Sean Carte wrote:<br>
<blockquote type=cite class=cite cite>Aha! I'm using $ARGV[0] where
you're using @ARGV:</blockquote>I did that too :-(<br><br>
<br>
I have written a object orientated perl module called Mailsend.pl.<br>
It give a very simple interface to sendmail and allows you to send HTML
formatted mail or plain or HTML and plain (multipart) and most
importantly attachments. <br>
The attachments bit is what makes it really usefully - attaching a file
in send mail is horrible and with this module you can write a simple perl
script to allow you to send attachments from the command line if you
want.<br>
It gives you control over things like the priority, from address, etc so
would also be a good start to a spam machine.<br><br>
It's not huge and is a very simple example of oop; both how to use it and
how to write one.<br><br>
The next step will be to replace sendmail with a built in SMTP engine
...<br><br>
You can perldoc it for instalation and usage stuff.<br><br>
&lt;SNIP&gt;<br><br>
#----------------------------------------------------------------<br>
# Title&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :
Mailsend.pm<br>
# Author&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Spike
spike@mweb.co.za<br>
# Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :
2003-03-04<br>
#<br>
# Description<br>
# -----------<br>
# This perl Module will provide a simple interface to Sendmail.<br>
# It must be copied to your library path.<br>
# To see a path list type:&nbsp; &quot;perl -e 'print
join(&quot;\n&quot;, @INC)'&quot;<br>
# Various methods allow a mail to be sent to multiple recipients<br>
# in plain text, html or both, with or without multiple 
attachments.<br>
# The only obligatory methods Mailsend-&gt;new() and&nbsp;
setTo(&quot;address&quot;). <br>
# If the style is set to html and only a setPlain message body is<br>
# specified the plain text message will be set to html with a
non-serif<br>
# font (more readable on screen) and any URLs will be expanded with<br>
# html tags to make them 'clickable'.<br>
# If the style is set to plain and only an html message body is set<br>
# an attempt to convert the html to plain text will be made. Note <br>
# that the results will probably be ugly.<br>
# If no style is set the setStyle will be defaulted to 'both' and <br>
# any necessary conversions made in accordance with the rules 
above.<br>
# A message with an attachment set with setAttach will have it's
style<br>
# set to 'both'. Attachments are base64 encoded.<br>
# A message &quot;priority can be set with setPriority. It can be set to
any<br>
# value but values fro 1-5 are supported by most clients. &quot;1&quot;
is highest, <br>
# &quot;5&quot; Lowest and &quot;3&quot; is Normal priority.<br>
# Code for subroutine 'old_encode_base64' taken from MIME::Base64<br>
# by Gisle Aas &lt;gisle@ActiveState.com&gt;. <br>
#<br>
# Examples <br>
# --------<br>
# $msg1 = Mailsend-&gt;new();<br>
#<br>
# $msg1-&gt;setTo('spike@mweb.com, recipient2@foo.com, ...');<br>
# $msg1-&gt;setSubject(&quot;$subject&quot;);<br>
# $msg1-&gt;setFrom('spike@mweb.co.za');<br>
# $msg1-&gt;setStyle('plain'); or 'html' or 'both'<br>
# $msg1-&gt;setPlain(&quot;$plain_message_text&quot;)<br>
# #msg1-&gt;sethtml(&quot;$html_message_code&quot;)<br>
# $msg1-&gt;setMailprog('/path/to/sendmail');<br>
# $msg1-&gt;setReplyto('sender@mweb.com');<br>
# $msg1-&gt;setCc('cc_recipient1@inode.co.za, cc_recipient2@inode.co.za,
...');<br>
# $msg1-&gt;setBcc('bcc_recipient1@inode.co.za,
bcc_recipient2@inode.co.za, ...');<br>
# $msg1-&gt;setAttach('/root/file1, /var/log/file2.txt, /home/me/file3,
...');<br>
# $msg1-&gt;setPriority('1') # 1 high to 5 low. 3 normal.<br>
#&nbsp; <br>
#<br>
# Change Control<br>
# ---------------<br>
# Date:&nbsp; 2003-03-o4<br>
# Author: Spike spike@mweb.co.za<br>
# Change: Initial version<br>
#<br><br>
package Mailsend;<br><br>
use <a href="file::Basename" eudora="autourl">File::Basename</a>;<br>
use strict;<br><br>
sub send <br>
{<br>
&nbsp;&nbsp;&nbsp; my (%self, @attachments, $file, $basefilename,
$encoded);<br><br>
&nbsp;&nbsp;&nbsp; my $self = shift;<br>
&nbsp;&nbsp;&nbsp; my ($die, $warn, $rv, $content_type,
$message);<br><br>
&nbsp;&nbsp;&nbsp; unless (defined $self-&gt;{Mailprog})<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $warn .= &quot;No mail program
defined\nI shall try and use a default\n&quot;;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chomp($rv = `which
sendmail`);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($rv !~ /no sendmail/)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$self-&gt;{Mailprog} = $rv;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $warn
.= &quot;I have set the Mailprog to $rv\n&quot;;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $die
.= &quot;I can't find a suitable Mailprog ... quiting\n&quot;;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }<br><br>
&nbsp;&nbsp;&nbsp; ($warn) &amp;&amp; (print $warn);<br>
&nbsp;&nbsp;&nbsp; ($die) &amp;&amp; (print $die) &amp;&amp; (exit
0);<br><br>
&nbsp;&nbsp;&nbsp; ($self-&gt;{Attach}) &amp;&amp; ($self-&gt;{Style} =
&quot;both&quot;);<br>
&nbsp;&nbsp;&nbsp; ($self-&gt;{Style}) || ($self-&gt;{Style} =
&quot;both&quot;);<br><br>
#-- plain only --#<br><br>
&nbsp;&nbsp;&nbsp; if ($self-&gt;{Style} =~ m/plain/i)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $content_type =
&quot;text/plain; charset=\&quot;us=ascii\&quot;\n\n&quot;;<br><br>
#-- get some plain content<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if((defined $self-&gt;{Html})
&amp;&amp; (! defined $self{Plain}))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$self-&gt;{Plain} = makeplain(&quot;$self-&gt;{Html}&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>
#-- build and send a plain only<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $message =
$self-&gt;{Plain};<br>
&nbsp;&nbsp;&nbsp; }<br><br>
#-- html only --#<br><br>
&nbsp;&nbsp;&nbsp; if ($self-&gt;{Style} =~ m/html/i)&nbsp; <br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $content_type = 'text/html;
charset=&quot;us=ascii&quot;';<br><br>
#-- get some html<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ((defined
$self-&gt;{Plain}) &amp;&amp; (! defined $self-&gt;{Html}))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$self-&gt;{Html} = makehtml(&quot;$self-&gt;{Plain}&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>
#-- build and send html only<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $message =
$self-&gt;{Html};<br>
&nbsp;&nbsp;&nbsp; }<br><br>
<br>
#-- both --#<br><br>
&nbsp;&nbsp;&nbsp; if ($self-&gt;{Style} =~ m/Both/i)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ((defined
$self-&gt;{Plain}) &amp;&amp; (! defined $self-&gt;{Html}))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$self-&gt;{Html} = makehtml(&quot;$self-&gt;{Plain}&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if((defined $self-&gt;{Html})
&amp;&amp; (! defined $self-&gt;{Plain}))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$self-&gt;{Plain} = makeplain(&quot;$self-&gt;{Html}&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $content_type =
'multipart/alternative;' .
qq{boundary=&quot;BoundaryPoodle&quot;};<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $message =
&quot;\n--BoundaryPoodle\nContent-Type: text/plain;
charset=\&quot;us=ascii\&quot;\n\n$self-&gt;{Plain}\n&quot;;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $message .=
&quot;\n--BoundaryPoodle\nContent-Type: text/html;
charset=\&quot;us=ascii\&quot;\n\n$self-&gt;{Html}\n&quot;;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #$message =
&quot;\n--BoundaryPoodle\nContent-Type: text/plain;
charset=\&quot;us=ascii\&quot;\nContent-Transfer-Encoding:
7bit\n\n$self-&gt;{Plain}\n&quot;;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #$message .=
&quot;\n--BoundaryPoodle\nContent-Type: text/html;
charset=\&quot;us=ascii\&quot;\nContent-Transfer-Encoding:
7bit\n\n$self-&gt;{Html}\n&quot;;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $message .=
&quot;\n--BoundaryPoodle--\n&quot;;<br>
&nbsp;&nbsp;&nbsp; }<br><br>
#-- attach--#<br><br>
&nbsp;&nbsp;&nbsp; if ($self-&gt;{Attach})<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $debug =
$self-&gt;{Attach};<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @attachments =
split(',',$self-&gt;{Attach});<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $content_type =
'multipart/mixed; ' . qq{boundary=&quot;mmBoundaryPoodle&quot;};<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $content_type .=
&quot;\n\n--mmBoundaryPoodle\n&quot;;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $content_type .=
'Content-Type: multipart/alternative; ' .
qq{boundary=&quot;BoundaryPoodle&quot;\n};<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach $file
(@attachments)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
chomp($file);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $file
=~ s/^\s+//g;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $file
=~ s/\s+$//g;<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$basefilename = basename($file);<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (-e
&quot;$file&quot;) || die(qq(I can't find file $file\n));<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
local($/) = undef;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
open(FILE, &quot;$file&quot;) or die &quot;$!&quot;;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$encoded = old_encode_base64(&lt;FILE&gt;);<br><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$message .= &quot;--mmBoundaryPoodle&quot;;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$message .= &quot;\nContent-Type: application/octet-stream;
name=\&quot;$basefilename\&quot;&quot;;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$message .= &quot;\nContent-Transfer-Encoding: base64&quot;;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$message .= &quot;\nContent-Disposition: attachment;
filename=\&quot;$basefilename\&quot;&quot;;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$message .= &quot;\n\n$encoded&quot;;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; close
FILE;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $message .=
&quot;--mmBoundaryPoodle--&quot;;<br>
&nbsp;&nbsp;&nbsp; }<br><br>
&nbsp;&nbsp;&nbsp; my $full_message = qq{From: $self-&gt;{From}\n};<br>
&nbsp;&nbsp;&nbsp; $full_message .= qq{To: $self-&gt;{To}\n};<br>
&nbsp;&nbsp;&nbsp; ($self-&gt;{Replyto}) &amp;&amp; ($full_message .=
qq{Reply-To: $self-&gt;{Replyto}\n});<br>
&nbsp;&nbsp;&nbsp; ($self-&gt;{Cc})&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&amp;&amp; ($full_message .= qq{Cc: $self-&gt;{Cc}\n});<br>
&nbsp;&nbsp;&nbsp; ($self-&gt;{Bcc})&nbsp;&nbsp;&nbsp;&nbsp; &amp;&amp;
($full_message .= qq{Bcc: $self-&gt;{Bcc}\n});<br>
&nbsp;&nbsp;&nbsp; ($self-&gt;{Subject}) &amp;&amp; ($full_message .=
qq{Subject: $self-&gt;{Subject}\n});<br>
&nbsp;&nbsp;&nbsp; $full_message .= &quot;Mime-Version: 
1.0\n&quot;;<br>
&nbsp;&nbsp;&nbsp; ($self-&gt;{Priority}) &amp;&amp; ($full_message .=
qq{X-Priority: $self-&gt;{Priority}\n});<br>
&nbsp;&nbsp;&nbsp; $full_message .= &quot;Content-Type:
$content_type\n&quot;;<br>
&nbsp;&nbsp;&nbsp; $full_message .= $message;<br><br>
&nbsp;&nbsp;&nbsp; open(SENDMAIL, &quot;|$self-&gt;{Mailprog} -oi
-t&quot;);<br>
&nbsp;&nbsp;&nbsp; print SENDMAIL &quot;$full_message&quot;;<br>
&nbsp;&nbsp;&nbsp; close SENDMAIL;<br>
}<br><br>
# constructor #<br><br>
sub new<br>
{<br>
&nbsp;&nbsp;&nbsp; my $class = shift;<br>
&nbsp;&nbsp;&nbsp; my $self = {};<br><br>
&nbsp;&nbsp;&nbsp; return bless $self, $class;<br>
}<br><br>
# methods #<br><br>
sub setStyle{<br>
&nbsp;&nbsp;&nbsp; my $self = shift;<br>
&nbsp;&nbsp;&nbsp; my $style = shift;<br>
&nbsp;&nbsp;&nbsp; $self-&gt;{Style} = $style<br>
}<br><br>
sub setPriority{<br>
&nbsp;&nbsp;&nbsp; my $self = shift;<br>
&nbsp;&nbsp;&nbsp; my $priority = shift;<br>
&nbsp;&nbsp;&nbsp; $self-&gt;{Priority} = $priority;<br>
}<br><br>
<br>
sub setHtml{<br>
&nbsp;&nbsp;&nbsp; my $self = shift;<br>
&nbsp;&nbsp;&nbsp; my $html = shift;<br>
&nbsp;&nbsp;&nbsp; $self-&gt;{Html} = $html;<br>
}<br><br>
sub setPlain{<br>
&nbsp;&nbsp;&nbsp; my $self = shift;<br>
&nbsp;&nbsp;&nbsp; my $plain = shift;<br>
&nbsp;&nbsp;&nbsp; $self-&gt;{Plain} = $plain;<br>
}<br><br>
sub setAttach{<br>
&nbsp;&nbsp;&nbsp; my $self = shift;<br>
&nbsp;&nbsp;&nbsp; my $attach = shift;<br>
&nbsp;&nbsp;&nbsp; $self-&gt;{Attach} = $attach;<br>
}<br><br>
sub setSubject{<br>
&nbsp;&nbsp;&nbsp; my $self = shift;<br>
&nbsp;&nbsp;&nbsp; my $subject = shift;<br>
&nbsp;&nbsp;&nbsp; $self-&gt;{Subject} = $subject;<br>
}<br><br>
sub setTo{<br>
&nbsp;&nbsp;&nbsp; my $self = shift;<br>
&nbsp;&nbsp;&nbsp; my $to = shift;<br>
&nbsp;&nbsp;&nbsp; $self-&gt;{To} = $to;<br>
}<br><br>
sub setFrom{<br>
&nbsp;&nbsp;&nbsp; my $self = shift;<br>
&nbsp;&nbsp;&nbsp; my $from = shift;<br>
&nbsp;&nbsp;&nbsp; $self-&gt;{From} = $from;<br>
}<br><br>
sub setCc{<br>
&nbsp;&nbsp;&nbsp; my $self = shift;<br>
&nbsp;&nbsp;&nbsp; my $cc = shift;<br>
&nbsp;&nbsp;&nbsp; $self-&gt;{Cc} = $cc;<br>
}<br><br>
sub setBcc{<br>
&nbsp;&nbsp;&nbsp; my $self = shift;<br>
&nbsp;&nbsp;&nbsp; my $bcc = shift;<br>
&nbsp;&nbsp;&nbsp; $self-&gt;{Bcc} = $bcc;<br>
}<br><br>
sub setMailprog{<br>
&nbsp;&nbsp;&nbsp; my $self = shift;<br>
&nbsp;&nbsp;&nbsp; my $mailprog = shift;<br>
&nbsp;&nbsp;&nbsp; $self-&gt;{Mailprog} = $mailprog;<br>
}<br><br>
sub setReplyto{<br>
&nbsp;&nbsp;&nbsp; my $self = shift;<br>
&nbsp;&nbsp;&nbsp; my $replyto = shift;<br>
&nbsp;&nbsp;&nbsp; $self-&gt;{Replyto} = $replyto;<br>
}<br><br>
sub makehtml<br>
{<br>
&nbsp;&nbsp;&nbsp; my $body = shift;<br><br>
&nbsp;&nbsp;&nbsp; $body =~ s/ftp:\S+/&lt;A
HREF=&quot;$&amp;&quot;&gt;$&amp;&lt;\/A&gt;/gs;<br>
&nbsp;&nbsp;&nbsp; $body =~ s/http:\S+/&lt;A
HREF=&quot;$&amp;&quot;&gt;$&amp;&lt;\/A&gt;/gs;<br>
&nbsp;&nbsp;&nbsp; $body =~ s/https:\S+/&lt;A
HREF=&quot;$&amp;&quot;&gt;$&amp;&lt;\/A&gt;/gs;<br>
&nbsp;&nbsp;&nbsp; my $htmlbody = &quot;&lt;PRE&gt;&lt;font
face=\&quot;Arial, Helvetica, sans-serif\&quot;&gt; $body
&lt;\/font&gt;&lt;\/PRE&gt;&quot;;<br><br>
&nbsp;&nbsp;&nbsp; return $htmlbody<br>
}<br><br>
sub makeplain<br>
{<br>
&nbsp;&nbsp;&nbsp; my ($line, $plaintext, @plain);<br><br>
&nbsp;&nbsp;&nbsp; my $html = shift;<br><br>
&nbsp;&nbsp;&nbsp; my @HTML = split(/(&lt;[^&gt;]*&gt;)/,
$html);<br><br>
&nbsp;&nbsp;&nbsp; foreach $line (@HTML)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $line =~ s/\n//g;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $line =~ s/^\s+//g;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $line =~ s/\s+$//g;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $line =~
s/&lt;\s*HR*&gt;/-----------------------------------------------------------\n/i;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ($line =~ m#&lt;\s*/TD&gt;#i)
&amp;&amp; push(@plain, &quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ($line =~ m#&lt;\s*/TR&gt;#i)
&amp;&amp; push(@plain, &quot;\n&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ($line =~
m#&lt;\s*TABLE&gt;#i) &amp;&amp; push(@plain, &quot;\n&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ($line =~ m#&lt;\s*BR&gt;#i)
&amp;&amp; push(@plain, &quot;\n&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ($line =~ m#&lt;\s*/DIV&gt;#i)
&amp;&amp; push(@plain, &quot;\n\n&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ($line =~ m#&lt;\s*/P&gt;#i)
&amp;&amp; push(@plain, &quot;\n\n&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ($line =~ m#&lt;*&gt;#)
&amp;&amp; (next);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; push(@plain,
&quot;$line&quot;);<br>
&nbsp;&nbsp;&nbsp; }<br><br>
&nbsp;&nbsp;&nbsp; $plaintext = join(' ', @plain);<br>
&nbsp;&nbsp;&nbsp; return $plaintext;<br><br>
}<br><br>
sub old_encode_base64 ($;$)<br>
{<br>
&nbsp;&nbsp;&nbsp; my $res = &quot;&quot;;<br>
&nbsp;&nbsp;&nbsp; my $eol = $_[1];<br>
&nbsp;&nbsp;&nbsp; $eol = &quot;\n&quot; unless defined $eol;<br>
&nbsp;&nbsp;&nbsp; pos($_[0]) =
0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# ensure start at the beginning<br><br>
&nbsp;&nbsp;&nbsp; $res = join '', map( pack('u',$_)=~ /^.(\S*)/,
($_[0]=~/(.{1,45})/gs));<br><br>
&nbsp;&nbsp;&nbsp; $res =~ tr|`
-_|AA-Za-z0-9+/|;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# `# help emacs<br>
&nbsp;&nbsp;&nbsp; # fix padding at the end<br>
&nbsp;&nbsp;&nbsp; my $padding = (3 - length($_[0]) % 3) % 3;<br>
&nbsp;&nbsp;&nbsp; $res =~ s/.{$padding}$/'=' x $padding/e if
$padding;<br>
&nbsp;&nbsp;&nbsp; # break encoded string into lines of no more than 76
characters each<br>
&nbsp;&nbsp;&nbsp; if (length $eol) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $res =~
s/(.{1,76})/$1$eol/g;<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; return $res;<br>
}<br><br>
<br>
1;<br><br>
__END__<br><br>
=head1 NAME<br><br>
Mailsend.pm<br><br>
=head1 SYNOPSIS<br><br>
<br>
&nbsp;$msg1 = Mailsend-&gt;new();<br><br>
<br>
&nbsp;$msg1-&gt;setTo('spike@mweb.com, recipient2@foo.com,
...');<br><br>
<br>
&nbsp;$msg1-&gt;setSubject(&quot;$subject&quot;);<br><br>
<br>
&nbsp;$msg1-&gt;setFrom('spike@mweb.co.za');<br><br>
<br>
&nbsp;$msg1-&gt;setStyle('plain'); or 'html' or 'both'<br><br>
<br>
&nbsp;$msg1-&gt;setPlain(&quot;$plain_message_text&quot;)<br><br>
<br>
&nbsp;#msg1-&gt;sethtml(&quot;$html_message_code&quot;)<br><br>
<br>
&nbsp;$msg1-&gt;setMailprog('/path/to/sendmail');<br><br>
<br>
&nbsp;$msg1-&gt;setReplyto('sender@mweb.com');<br><br>
<br>
&nbsp;$msg1-&gt;setCc('cc_recipient1@inode.co.za,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
cc_recipient2@inode.co.za,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
...');<br><br>
<br>
&nbsp;$msg1-&gt;setBcc('bcc_recipient1@inode.co.za,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
bcc_recipient2@inode.co.za,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
...');<br><br>
<br>
&nbsp;$msg1-&gt;setAttach('/root/file1, /var/log/file2.txt,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/home/me/file3, ...');<br><br>
<br>
&nbsp;$msg1-&gt;setPriority('1') # 1 high to 5 low. 3 normal.<br><br>
<br>
&nbsp;$msg1-&gt;send();<br><br>
=head1 DESCRIPTION<br><br>
<br>
This perl Module will provide a simple interface to Sendmail.<br>
It must be copied to your library path.<br>
To see a path list type:&nbsp; &quot;perl -e 'print join(&quot;\n&quot;,
@INC)'&quot;<br><br>
Various methods allow a mail to be sent to multiple recipients<br>
in plain text, html or both, with or without multiple attachments.<br>
The only obligatory methods Mailsend-&gt;new() and&nbsp;
setTo(&quot;address&quot;)<br>
and send().<br><br>
If the style is set to html and only a setPlain message body is<br>
specified the plain text message will be set to html with a
non-serif<br>
font (more readable on screen) and any URLs will be expanded with<br>
html tags to make them 'clickable'.<br><br>
If the style is set to plain and only an html message body is set<br>
an attempt to convert the html to plain text will be made. Note<br>
that the results will probably be ugly.<br><br>
If no style is set the setStyle will be defaulted to 'both' and<br>
any necessary conversions made in accordance with the rules
above.<br><br>
A message with an attachment set with setAttach will have it's 
style<br>
set to 'both'. Attachments are base64 encoded.<br><br>
A message &quot;priority can be set with setPriority. It can be set to
any<br>
value but values fro 1-5 are supported by mosr clients. &quot;1&quot; is
highest,<br>
&quot;5&quot; Lowest and &quot;3&quot; is Normal priority.<br><br>
Code for subroutine 'old_encode_base64' taken from MIME::Base64<br>
by Gisle Aas &lt;gisle@ActiveState.com&gt;.<br><br>
<br>
=cut<br><br>
<br>
&lt;SNIP&gt;<br><br>
<br><br>
<br><br>
<br><br>
<x-sigsep><p></x-sigsep>
<tt><font face="Courier New, Courier" size=2>Spike Hodge<br><br>
UNIX Programmer<br>
</font></tt><font face="Courier New, Courier" size=2>M-Web
Technology<br>
</font><tt>021 596 8496<br>
082 901 5265<br><br>
</tt>Click here and make M-Web your homepage<br>
<a href="http://homepage.mweb.co.za/" eudora="autourl">http://homepage.mweb.co.za</a></body>
</html>