Mitchel Verschoof
Mitchel Verschoof

Reputation: 1508

SwiftMailer Spool Transport

In symfony 2, if I create a new swiftmessage instance I can give the transport in it.

$email = \Swift_Message::newInstance( $transport )

But how to put the transport in it and how to configure? (like spool path)

I tried:

$transport = new \Swift_Transport_SpoolTransport();

Catchable Fatal Error: Argument 1 passed to Swift_Transport_SpoolTransport::__construct() must be an instance of Swift_Events_EventDispatcher, none given, called in /Users/mitchel/Projecten/Refurls/src/Refurl/FrontendBundle/Controller/MessageController.php on line 67 and defined in /Users/mitchel/Projecten/Refurls/vendor/swiftmailer/lib/classes/Swift/Transport/SpoolTransport.php line 27

so I think I don't use the right class. Who can push me the right way? =)


The next code also send it directly

$transport = new \Swift_FileSpool( '../app/spool' );
$email = \Swift_Message::newInstance( $transport )

I figured out that the Swift_Message doesn't expect a tranport.

public function __construct($subject = null, $body = null,
    $contentType = null, $charset = null)

It would be nice to give a Transport. The reason that I don't want to configure it in the config is that if I create 2 services and 1 with:

<argument type="service" id="swiftmailer.transport.real" />

This transport.real will ignore the swiftmailer.delivery_address.

Upvotes: 1

Views: 3408

Answers (2)

lemonSkip
lemonSkip

Reputation: 54

the Swift_Transport_SpoolTransport requires two arguments (source: http://apigen.juzna.cz/doc/swiftmailer/swiftmailer/class-Swift_Transport_SpoolTransport.html):

  1. Swift_Events_EventDispatcher $eventDispatcher
  2. Swift_Spool $spool = null

For the first argument I used this class:

new \Swift_Events_SimpleEventDispatcher();

Simplez!

Upvotes: 1

Elnur Abdurrakhimov
Elnur Abdurrakhimov

Reputation: 44851

You do all the configuration in the config.yml file and create a message without passing anything to the factory method:

$message = Swift_Message::newInstance();

Upvotes: 0

Related Questions