hesco has asked for the wisdom of the Perl Monks concerning the following question:
-- Hugh
Update
Thanks folks. I'm starting to toy around the edges with refactoring some code I wrote years ago and stretched and prodded at for a long time. Its been installed on three or five servers so far that I am aware of. You're seeing small pieces of it. This routine was pulled from a cgi script and has just been dropped into a module with a proper ->new() constructor. My $self = { }; above was simply an adaptation to create something runnable.
Thanks VSarkiss. That was helpful.
My error messages and a runnable snippet follows.
And the code I'm working with should run as this:[Fri Oct 13 07:32:42 2006] [error] [client 192.168.1.102] sh: -c: line + 1: syntax error near unexpected token `newline' [Fri Oct 13 07:32:42 2006] [error] [client 192.168.1.102] sh: -c: line + 1: `/usr/sbin/sendmail -f script-cgi@tld.hostname.com him@thatone.ex +ample.net,her@theotherone.example.net "Coordinator's Name" <test@mydo +main.com>' [Fri Oct 13 07:32:42 2006] [error] [client 192.168.1.102] Now sending +email using the `sendmail` method.
#!/usr/bin/perl -w use strict; use Mail::Mailer; my $self = {}; my $from = "script-cgi\@tld.hostname.com"; my $to = "him\@thatone.example.net,her\@theotherone.example.net"; my $cc = "\"Coordinator's Name\" <test\@mydomain.com>"; my $subject = "Test sendemail path"; my $email_method = "sendmail"; my $msg =<<EOM; This is a test message. This is only a test. EOM &sendemail($self,$from,$to,$cc,$subject,$msg,$email_method); 1; sub sendemail() { my($self,$from,$to,$cc,$subject,$msg,$email_method)=@_; my($hdr,$qmail,$sendmail); chomp($from); chomp($to); chomp($cc); $qmail = "/var/qm/bin/qmail-inject"; $sendmail = "/usr/sbin/sendmail -f $from $to $cc"; if($email_method eq "qmail"){ # code similiar to the next case } elsif ($email_method eq "sendmail") { $hdr =<<EOH; From: $from To: $to Cc: $cc Subject: $subject EOH open (MAILER, "|$sendmail" ) || die "Unable to open sendmail"; print MAILER ( $hdr, $msg ); close MAILER; print STDERR "Now sending email using the `sendmail` method."; return 1; } elsif ($email_method eq "mailer") { my $mailer = Mail::Mailer->new(); $mailer->open({ From => "$from", To => "$to", Cc => "$cc", Subject => "$subject", }) or die "Can not open: $! \n"; print $mailer $msg; $mailer->close(); return 1; } else { return 0; } } # END sendemail()
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unexpected 'newline' token breaks sendmail.
by VSarkiss (Monsignor) on Oct 13, 2006 at 16:41 UTC | |
by Anonymous Monk on Oct 13, 2006 at 17:46 UTC | |
|
Re: Unexpected 'newline' token breaks sendmail.
by davido (Cardinal) on Oct 13, 2006 at 16:00 UTC | |
|
Re: Unexpected 'newline' token breaks sendmail.
by Fletch (Bishop) on Oct 13, 2006 at 16:18 UTC |