Hello.
I wanted to learn about my options for emailing from within a Perl script.
I have installed the modules Mail::Sendmail and Mail::Sender and am
currently experimenting with the method MailFile in module Mail::Sender.
The main example I wanted to be able to work through with this method
was to send multiple attachments to multiple recipients and build the
email body from the contents of some text file. I have been able to do
this. However, my goal is to have a generic email subroutine that...
1) may or may not have a subject line
2) may have 0, 1, or more than 1 attachments
3) may have no body, may have a body that is simply a
string passed in as a parameter, or may have a
body that comes from the contents of a text file
whose name is passed in.
I'm thinking of structuring the subroutine something like this:
sub send_email
{
my ($from, $to, $subject, $body_type, $body, $attachment) = @_;
my $body_string = "";
my $send_email_status = 0;
my $send_email_err = "";
if ($body_type -eq 1)
{
$body_string = $body;
}
elseif ($body_type -eq 2)
{
Open text file whose name is given by $body and read its
contents into $body_string
}
my $sender_obj = new Mail::Sender
{
smtp => <fill in>
}
$sender_obj->MailFile(
{
from => $from,
to => $to,
subject => $subject,
msg => $body_string,
file => $attachment
});
$send_email_err = $Mail::Sender::Error;
if ($send_mail_err)
{
printf "Error sending email: %s\n", $send_email_err;
$send_email_status = -1;
}
return $send_email_status;
}
If I have no attachment and pass in a null string for the attachment
parameter, will the method MailFile interpret this correctly or error
out?
If I pass in a 0 for the body type to indicate that this message has
no body, will this method know how to interpret a null string assigned
to variable "msg" or error out?
Finally, if I use a null string for the email subject, will this
method be okay with it?
Thanks.
Tony Thomas
----------------------------------------------------------------------------
-------------
Anthony Thomas
Senior Programmer Analyst
Affinity Group, Inc.
64 Inverness Drive East
Englewood, CO 80112
(303) 728-7432
[EMAIL PROTECTED]
www.affinitygroup.com
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users