P
P
Pavel K2017-07-04 01:00:35
Mail server
Pavel K, 2017-07-04 01:00:35

Is there a "ready, lightweight" local mail server for debugging scripts?

Greetings!
Is there a "ready, lightweight" mail server (installation in one package that does not require a bunch of settings a la Postfix)?
Wishlist are:
1. The ability to connect ordinary clients
2. Purely "local" without using external existing accounts.
3. Easy simple installation, easy creation of test accounts.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2017-07-04
@PavelK

If quite primitive, then in php.ini

[mail function]
sendmail_from = me@example.com
sendmail_path = "php /path/to/sendmail_simple_emulator.php"

And inside something like:
$MailDir = __DIR__.'/log/'; // папка для сохранения писем
if (!is_dir($MailDir)) {
  mkdir($MailDir, 0644);
}

$data = "";
$line = 'foo';

$f = fopen("php://stdin", "r"); 	
while( !feof($f) AND ($line!='') ) { 
  $line = fgets($f,255); 
  $data .= $line;
} 
fclose($f);

$data = str_replace("\r", '', $data);
$data = str_replace("\n", PHP_EOL, $data);

$i = 0;
$addon = '';
while ( file_exists( $fname = ($MailDir.'/'.date('Y-m-d-H-i-s').$addon.'.eml') )) {
  $addon = '-' . ++$i;
}

file_put_contents($fname, $data);

The output is a folder with .eml files.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question