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

[msmtp-users] Wrapper for msmtp. Writes a mail to procmail on failure



  Please ignore my last mail

  Does msmtp have some trigger which will execute certain commands if the mail send is not successful?
 
   Anyway I just hacked up a php script which is a wrapper over msmtp. It will execute msmtp and if the command fails, it will just pipe an error message to procmail. You can configure your procmail to deliver the msmtp error messages to a separate mailbox, and thus you will have the full functionality of a smtp server itself. CUrrently it becomes sort of irritable trying to figure out if the mail really went or not.

   Thanks.
 
    attached msmptp.php
 

#!/usr/bin/php
<?php 

while (!feof(STDIN)) {
	$content .= fread(STDIN, 8192);
}

unset($argv[0]);

$args = implode(" ", $argv);

$file = tempnam("/tmp", "msmtp");
$errfile = tempnam("/tmp", "msmtp.err");
$outfile = tempnam("/tmp", "msmtp.out");
file_put_contents($file, $content);
system("msmtp --debug  $args < $file >$outfile 2>$errfile", $return);
unlink($file);

if ($return) {
	$out = file_get_contents($outfile);
	$err = file_get_contents($errfile);
	$mes = "\nReturned Mail-----------------------------\n$content";
	$var = "From Msmtp " . date("D M d h:i:s Y") . "\n";
	$var .= "From: Msmtp CHeck<msmtp@...21...>\n";
	$var .= "Subject: Msmtp CHeck\n";
	$var .= "To: root@...18...\n";
	//$var .= "Date: " . date("d, M Y");
	$var .= "Date: " . date("D, d M Y h:i:s") . "\n";
	$var .= "\n";
	$var .= $mes;
	$var .= "\n---------------------------------Errror\n";
	$var .= $err;
	$var .= $out;
	$tmpfile = tempnam("/tmp", "msmtp");
	file_put_contents($tmpfile, $var);
	system("procmail < $tmpfile");
	unlink($tmpfile);
}

unlink($errfile);