Send emails via memory in controllers and spool in

2020-04-16 19:39发布

I need to use the spool option to send massive emails to my users, but i won't to change whole config of my app to spool because my register system send an email to the user and i want that this email be instant send.

Is any way to do this without change the global config for swiftmailer?

1条回答
狗以群分
2楼-- · 2020-04-16 19:56

You can configure different emailers. For example:

swiftmailer:
    default_mailer: spool_mailer
    mailers:
        spool_mailer:
            spool:
                type: file
                path: /path/to/spool
            # ...
        instant_mailer:
            # ... 

Then use one emailer or the other depending on whether you want to spool or not:

//in your controller
$spoolMailer = $this->get('swiftmailer.mailer.spool_mailer');
$spoolMailer->send(...);  //this will be spooled

$instantMailer = $this->get('swiftmailer.mailer.instant_mailer');
$instantMailer->send(...);  //this will be sent instantly
查看更多
登录 后发表回答