Skip to content

Commit

Permalink
FileMailer use nette/utils
Browse files Browse the repository at this point in the history
  • Loading branch information
h4kuna authored and f3l1x committed Aug 28, 2023
1 parent d358d3f commit bd47814
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/Mailer/FileMailer.php
Expand Up @@ -2,27 +2,21 @@

namespace Contributte\Mail\Mailer;

use Contributte\Mail\Exception\RuntimeException;
use Nette\Mail\Mailer;
use Nette\Mail\Message;
use Nette\Utils\FileSystem;

class FileMailer implements Mailer
{

private string $path;

public function __construct(string $path)
public function __construct(private string $path)
{
if (!is_dir($path) && !mkdir($path, 0777, true)) {
throw new RuntimeException(sprintf('Directory "%s" was not created', $path));
}

$this->path = realpath($path) . DIRECTORY_SEPARATOR;
FileSystem::createDir($this->path);
}

public function send(Message $mail): void
{
file_put_contents($this->path . date('Y-m-d H-i-s') . microtime() . '.eml', $mail->generateMessage());
file_put_contents($this->path . '/' . date('Y-m-d H-i-s') . microtime() . '.eml', $mail->generateMessage());
}

}

0 comments on commit bd47814

Please sign in to comment.