3

I need 2 kind of mails:

  1. Spool mail (for bulk mails)
  2. Direct mail (like a register mail)

Now I have 2 services:

<service id="spool_mailer" class="%swiftmailer.class%">
    <argument type="service" id="swiftmailer.transport"/>
</service>

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

But the "swiftmailer.transport.real" will ignore the "swiftmailer.delivery_address" and in the dev env its required. I have tried other transports but they will spool the mail: Configure SwiftMailer

How to fix this?

Mitchel Verschoof
  • 1,543
  • 4
  • 20
  • 38
  • works for me.. are you sure you are testing this properly? – Ramon de la Fuente Oct 30 '12 at 10:57
  • I stand corrected: in your setup, if you only load the "mailer" service the delivery_address will not be used. If you load the "spool_mailer" service (but still use the mailer service to send your message) the delivery_address *will* be used. – Ramon de la Fuente Oct 30 '12 at 12:03

1 Answers1

0

I think your solution, while clever, is hacky and relies on bypassing some of Swiftmailer's internal functionality. Bypassing the part of the code that sends the email to the spool seems to also be bypassing the part of the code that sets the delivery address. I wouldn't do this without reading the source code to get a clear idea what else isn't happening.

I think the supported approach is to use multiple mailers as described here: http://symfony.com/doc/current/reference/configuration/swiftmailer.html#using-multiple-mailers

This will allow you to define two different mailers, one of which can be configured to use a spool. (You can also have two mailers that each have their own separate spool)

Omn
  • 2,982
  • 1
  • 26
  • 39