diff --git a/lib/WebGUI/Mail.pm b/lib/WebGUI/Mail.pm index 63a5393d3..2355a08a9 100644 --- a/lib/WebGUI/Mail.pm +++ b/lib/WebGUI/Mail.pm @@ -19,26 +19,34 @@ use WebGUI::Session; #eg: send("jt@jt.com","hi, how are you","this is my message","bob@bob.com"); #eg: send(to,subject,message,cc); sub send { - my ($smtp); - $smtp = Net::SMTP->new($session{setting}{smtpServer}); # connect to an SMTP server - if (defined $smtp) { - $smtp->mail($session{setting}{companyEmail}); # use the sender's address here - $smtp->to($_[0]); # recipient's address - $smtp->data(); # Start the mail - # Send the header. - $smtp->datasend("To: ".$_[0]."\n"); - $smtp->datasend("From: $session{setting}{companyName} <$session{setting}{companyEmail}>\n"); - $smtp->datasend("CC: $_[3]\n") if ($_[3]); - $smtp->datasend("Subject: ".$_[1]."\n"); - $smtp->datasend("\n"); - # Send the body. - $smtp->datasend($_[2]); - $smtp->datasend("\n\n $session{setting}{companyName}\n $session{setting}{companyEmail}\n $session{setting}{companyURL}\n"); - $smtp->dataend(); # Finish sending the mail - $smtp->quit; # Close the SMTP connection - } else { - WebGUI::ErrorHandler::warn("Couldn't connect to mail server: ".$session{setting}{smtpServer}); - } + my ($smtp, $message); + #header + $message = "To: ".$_[0]."\n"; + $message .= "From: $session{setting}{companyName} <$session{setting}{companyEmail}>\n"; + $message .= "CC: $_[3]\n" if ($_[3]); + $message .= "Subject: ".$_[1]."\n"; + $message .= "\n"; + #body + $message .= $_[2]."\n"; + #footer + $message .= "\n $session{setting}{companyName}\n $session{setting}{companyEmail}\n $session{setting}{companyURL}\n"; + if ($session{setting}{smtpServer} =~ /\/sendmail/) { + open(MAIL,'| '.$session{setting}{smtpServer}.' -t -oi') or WebGUI::ErrorHandler::warn("Couldn't connect to mail server: ".$session{setting}{smtpServer}); + print MAIL $message; + close(MAIL); + } else { + $smtp = Net::SMTP->new($session{setting}{smtpServer}); # connect to an SMTP server + if (defined $smtp) { + $smtp->mail($session{setting}{companyEmail}); # use the sender's address here + $smtp->to($_[0]); # recipient's address + $smtp->data(); # Start the mail + $smtp->datasend($message); + $smtp->dataend(); # Finish sending the mail + $smtp->quit; # Close the SMTP connection + } else { + WebGUI::ErrorHandler::warn("Couldn't connect to mail server: ".$session{setting}{smtpServer}); + } + } } diff --git a/lib/WebGUI/Operation/Settings.pm b/lib/WebGUI/Operation/Settings.pm index bbb6cf81e..5ad52807b 100644 --- a/lib/WebGUI/Operation/Settings.pm +++ b/lib/WebGUI/Operation/Settings.pm @@ -39,13 +39,13 @@ sub www_editUserSettings { $output .= '