Latest release: v0.2.0

Mail

✨ Extra contribution to nette/mail.

Content

MailExtension

You have to manually register this extension in the first place.

Be careful, nette/mail is registered by default under the mail key, that's why we have picked the post key.

Simple example:

extensions:
    post: Contributte\Mail\DI\MailExtension
    
post:
    # Required option
    mailer: Contributte\Mail\Mailer\FileMailer(%tempDir%/mails)
    
    # Optional options
    debug: %debugMode% #shows sent emails in Tracy
    mode: standalone

1
2
3
4
5
6
7
8
9
10
11

There are several mailer implementations:

post:
    mailer: Contributte\Mail\Mailer\FileMailer(%tempDir%/mails)
    
    mailer:
      class: Contributte\Mail\Mailer\SendmailMailer
      setup:
        - setBounceMail(mail@contributte.org)
        
    mailer: Contributte\Mail\Mailer\DevOpsMailer(dev@contributte.org)
    
    mailer:
      class: Contributte\Mail\Mailer\CompositeMailer
      arguments: [silent: false] # If silent is enabled then exceptions from mailers are catched
      setup:
        - add(@mailer1)
        - add(@mailer2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

As you can see, the extension has two modes:

post:
  mode: standalone
  # OR
  mode: override
1
2
3
4
  • standalone (default)
  • override

Standalone

Disables autowiring of both nette.mailer and mail.mailer.

Override

Drops nette.mailer and mail.mailer services and aliases them to post.mailer.

Debug

The extension has also optional debug option that shows a Tracy panel with sent mail headers and full preview.

Mailers

FileMailer

Stores emails on your file system.

$mailer = new FileMailer(__DIR__ . '/temp/mails');
1

SendmailMailer

This is the default Nette\Mail\SendmailMailer with some extra methods and fields.

Bounce mail

$mailer->setBounceMail('mail@contributte.org')
1

Events

$mailer->onSend[] = function($mailer, $message) {}
1

DevOpsMailer

Sends all emails to one address with preserved original attributes.

$mailer = new DevOpsMailer('dev@contributte.org');
1

DevNullMailer

Does literally nothing.

$mailer = new DevNullMailer();
1

CompositeMailer

Combines more mailers together.

$mailer = new CompositeMailer($silent = false); // If silent is enabled then exceptions from mailers are caught
$mailer->add(new FileMailer(__DIR__ . '/temp/mails'));
$mailer->add(new DevOpsMailer('dev@contributte.org'));
1
2
3

TraceableMailer

Internally wraps your mailer and displays sent mails when the debug option is set to true in a Tracy panel.

Message

Message::addTos(array $tos)

This wrapper accepts an array of recipients and calls addTo on each one of them.