[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Changing a Unix script



>I am not a perl scripter and I have a client who is just learning, 
>He has a Unix form processing script that we >cannot make work 
>because it wants a path to sendmail. The offending lines are below.
>
># change this to the proper location of sendmail on your system:
>$mailprog = '/usr/sbin/sendmail';
>
>On a Mac these paths don't exist so how do I change them to use my 
>Mac mailserver. Thanks in advance.
>========================================================================
>
>Andrew Johnson
>Systems Administrator         WestWorld Computers Ltd.
>Voice 780 454 5190            10333 170 St.
>Fax   780 453 5174            Edmonton, AB  T5P 4V4
>Visit us at www.westworld.ca
>
>------------------------------------------------------------------------
>


Hi Andrew,

making the script work is not as simple as changing a single line. 
The standard Unix mail program sendmail doesn't exist on the Mac. The 
Unix way of doing email, e.g.

open EMAIL,"|/usr/sbin/sendmail -t" or die "Unable to fork sendmail";
print EMAIL "To: $recipient\n";
print EMAIL "From: $name\n";
print EMAIL "Subject: $subj\n\n";
print EMAIL "$messagebody\n";
close EMAIL;

has to be changed. You will need to use a mail module. There are 
various packages on CPAN for sending mail (like Net::SMTP, 
Mail::Internet (requires Net::SMTP), etc.), which are available from
http://www.perl.com/CPAN-local/modules/by-category/19_Mail_and_Usenet_News/Mail/

For simple mail sending the module Mail::Sendmail, which has nothing 
to do with the Unix sendmail program, should do what you want. 
Example:

use Mail::Sendmail;

%mail = (	To      => 'toms_email@gmx.de',
	From    => 'Andrewj@westworld.ca',
	Message => "Yet another mail."
	);

sendmail(%mail) or die $Mail::Sendmail::error;

__END__

The SMTP host is saved in the module file by default, or you can pass 
it in the hash as "smtp => 'smtp.mail.com' " . Read the module's 
documentation for details.

Hope that helps.

Best regards,

--Thomas


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org