0
votes

I have the sonata notification setup and I tried to use the sonata admin mailer consumer however when in doctrine mode the notification gets consumed but the e-mail doesn't get sent at all, when I set it to postpone or runtime mode the mail does get sent. Any idea's why this would be?

I have looked at this solution (sonataNotificationBundle, emails getting stored to database but swiftmailer consumer is not triggered and no emails are sent) but it isn't the same issue as mine.

config.yml

# Swiftmailer Configuration
swiftmailer:
   transport: %mailer_transport%
   host:      %mailer_host%
   username:  %mailer_user%
   password:  %mailer_password%
   spool:     { type: memory }
   logging:   %kernel.debug%
   port:      %mailer_port%
   encryption: %mailer_encryption%

Log files for two consumed mailer messages:

[2014-03-25 11:39:30] doctrine.DEBUG: SELECT n0_.type AS type0, n0_.body AS body1, n0_.state AS state2, n0_.restart_count AS restart_count3, n0_.created_at AS created_at4, n0_.updated_at AS updated_at5, n0_.started_at AS started_at6, n0_.completed_at AS completed_at7, n0_.id AS id8 FROM notification__message n0_ WHERE n0_.state = ? ORDER BY n0_.created_at ASC LIMIT 10 [0] []
[2014-03-25 11:39:30] doctrine.DEBUG: "START TRANSACTION" [] []
[2014-03-25 11:39:30] doctrine.DEBUG: UPDATE notification__message SET state = ?, started_at = ? WHERE id = ? [1,"2014-03-25 11:39:30",59] []
[2014-03-25 11:39:30] doctrine.DEBUG: "COMMIT" [] []
[2014-03-25 11:39:30] doctrine.DEBUG: SELECT t0.id AS id1, t0.title AS title2, t0.page_title AS page_title3, t0.page_description AS page_description4, t0.form_fields AS form_fields5, t0.slug AS slug6, t0.created AS created7, t0.business_name AS business_name8, t0.bcc_users AS bcc_users9, t0.has_limit AS has_limit10, t0.deal_limit AS deal_limit11, t0.promotion_image_id AS promotion_image_id12, t0.page_logo_id AS page_logo_id13, t0.customer_id AS customer_id14 FROM promotions t0 WHERE t0.id = ? [1] []
[2014-03-25 11:39:30] doctrine.DEBUG: SELECT t0.id AS id1, t0.user AS user2, t0.created AS created3, t0.attempts AS attempts4, t0.messageSent AS messageSent5, t0.updated AS updated6, t0.promotion_id AS promotion_id7 FROM promotions_result t0 WHERE t0.id = ? [38] []
[2014-03-25 11:39:30] doctrine.DEBUG: "START TRANSACTION" [] []
[2014-03-25 11:39:30] doctrine.DEBUG: UPDATE promotions_result SET attempts = ?, messageSent = ?, updated = ? WHERE id = ? [1,"true","2014-03-25 11:39:30",38] []
[2014-03-25 11:39:30] doctrine.DEBUG: "COMMIT" [] []
[2014-03-25 11:39:30] doctrine.DEBUG: "START TRANSACTION" [] []
[2014-03-25 11:39:30] doctrine.DEBUG: UPDATE notification__message SET state = ?, completed_at = ? WHERE id = ? [2,"2014-03-25 11:39:30",59] []
[2014-03-25 11:39:30] doctrine.DEBUG: "COMMIT" [] []
[2014-03-25 11:39:30] doctrine.DEBUG: "START TRANSACTION" [] []
[2014-03-25 11:39:30] doctrine.DEBUG: UPDATE notification__message SET state = ?, started_at = ? WHERE id = ? [1,"2014-03-25 11:39:30",58] []
[2014-03-25 11:39:30] doctrine.DEBUG: "COMMIT" [] []
[2014-03-25 11:39:30] doctrine.DEBUG: SELECT t0.id AS id1, t0.user AS user2, t0.created AS created3, t0.attempts AS attempts4, t0.messageSent AS messageSent5, t0.updated AS updated6, t0.promotion_id AS promotion_id7 FROM promotions_result t0 WHERE t0.id = ? [37] []
[2014-03-25 11:39:30] doctrine.DEBUG: "START TRANSACTION" [] []
[2014-03-25 11:39:30] doctrine.DEBUG: UPDATE promotions_result SET attempts = ?, messageSent = ?, updated = ? WHERE id = ? [1,"true","2014-03-25 11:39:30",37] []
[2014-03-25 11:39:30] doctrine.DEBUG: "COMMIT" [] []
[2014-03-25 11:39:30] doctrine.DEBUG: "START TRANSACTION" [] []
[2014-03-25 11:39:30] doctrine.DEBUG: UPDATE notification__message SET state = ?, completed_at = ? WHERE id = ? [2,"2014-03-25 11:39:30",58] []
[2014-03-25 11:39:30] doctrine.DEBUG: "COMMIT" [] []
[2014-03-25 11:39:30] doctrine.DEBUG: SELECT n0_.type AS type0, n0_.body AS body1, n0_.state AS state2, n0_.restart_count AS restart_count3, n0_.created_at AS created_at4, n0_.updated_at AS updated_at5, n0_.started_at AS started_at6, n0_.completed_at AS completed_at7, n0_.id AS id8 FROM notification__message n0_ WHERE n0_.state = ? ORDER BY n0_.created_at ASC LIMIT 10 [0] []
[2014-03-25 11:39:31] doctrine.DEBUG: SELECT n0_.type AS type0, n0_.body AS body1, n0_.state AS state2, n0_.restart_count AS restart_count3, n0_.created_at AS created_at4, n0_.updated_at AS updated_at5, n0_.started_at AS started_at6, n0_.completed_at AS completed_at7, n0_.id AS id8 FROM notification__message n0_ WHERE n0_.state = ? ORDER BY n0_.created_at ASC LIMIT 10 [0] []
[2014-03-25 11:39:31] doctrine.DEBUG: SELECT n0_.type AS type0, n0_.body AS body1, n0_.state AS state2, n0_.restart_count AS restart_count3, n0_.created_at AS created_at4, n0_.updated_at AS updated_at5, n0_.started_at AS started_at6, n0_.completed_at AS completed_at7, n0_.id AS id8 FROM notification__message n0_ WHERE n0_.state = ? ORDER BY n0_.created_at ASC LIMIT 10 [0] []
[2014-03-25 11:39:32] doctrine.DEBUG: SELECT n0_.type AS type0, n0_.body AS body1, n0_.state AS state2, n0_.restart_count AS restart_count3, n0_.created_at AS created_at4, n0_.updated_at AS updated_at5, n0_.started_at AS started_at6, n0_.completed_at AS completed_at7, n0_.id AS id8 FROM notification__message n0_ WHERE n0_.state = ? ORDER BY n0_.created_at ASC LIMIT 10 [0] []
[2014-03-25 11:39:32] doctrine.DEBUG: SELECT n0_.type AS type0, n0_.body AS body1, n0_.state AS state2, n0_.restart_count AS restart_count3, n0_.created_at AS created_at4, n0_.updated_at AS updated_at5, n0_.started_at AS started_at6, n0_.completed_at AS completed_at7, n0_.id AS id8 FROM notification__message n0_ WHERE n0_.state = ? ORDER BY n0_.created_at ASC LIMIT 10 [0] []
[2014-03-25 11:39:33] doctrine.DEBUG: SELECT n0_.type AS type0, n0_.body AS body1, n0_.state AS state2, n0_.restart_count AS restart_count3, n0_.created_at AS created_at4, n0_.updated_at AS updated_at5, n0_.started_at AS started_at6, n0_.completed_at AS completed_at7, n0_.id AS id8 FROM notification__message n0_ WHERE n0_.state = ? ORDER BY n0_.created_at ASC LIMIT 10 [0] []
[2014-03-25 11:39:33] doctrine.DEBUG: SELECT n0_.type AS type0, n0_.body AS body1, n0_.state AS state2, n0_.restart_count AS restart_count3, n0_.created_at AS created_at4, n0_.updated_at AS updated_at5, n0_.started_at AS started_at6, n0_.completed_at AS completed_at7, n0_.id AS id8 FROM notification__message n0_ WHERE n0_.state = ? ORDER BY n0_.created_at ASC LIMIT 10 [0] []
[2014-03-25 11:39:34] doctrine.DEBUG: SELECT n0_.type AS type0, n0_.body AS body1, n0_.state AS state2, n0_.restart_count AS restart_count3, n0_.created_at AS created_at4, n0_.updated_at AS updated_at5, n0_.started_at AS started_at6, n0_.completed_at AS completed_at7, n0_.id AS id8 FROM notification__message n0_ WHERE n0_.state = ? ORDER BY n0_.created_at ASC LIMIT 10 [0] []
[2014-03-25 11:39:34] doctrine.DEBUG: SELECT n0_.type AS type0, n0_.body AS body1, n0_.state AS state2, n0_.restart_count AS restart_count3, n0_.created_at AS created_at4, n0_.updated_at AS updated_at5, n0_.started_at AS started_at6, n0_.completed_at AS completed_at7, n0_.id AS id8 FROM notification__message n0_ WHERE n0_.state = ? ORDER BY n0_.created_at ASC LIMIT 10 [0] []
[2014-03-25 11:39:35] doctrine.DEBUG: SELECT n0_.type AS type0, n0_.body AS body1, n0_.state AS state2, n0_.restart_count AS restart_count3, n0_.created_at AS created_at4, n0_.updated_at AS updated_at5, n0_.started_at AS started_at6, n0_.completed_at AS completed_at7, n0_.id AS id8 FROM notification__message n0_ WHERE n0_.state = ? ORDER BY n0_.created_at ASC LIMIT 10 [0] []
[2014-03-25 11:39:35] doctrine.DEBUG: SELECT n0_.type AS type0, n0_.body AS body1, n0_.state AS state2, n0_.restart_count AS restart_count3, n0_.created_at AS created_at4, n0_.updated_at AS updated_at5, n0_.started_at AS started_at6, n0_.completed_at AS completed_at7, n0_.id AS id8 FROM notification__message n0_ WHERE n0_.state = ? ORDER BY n0_.created_at ASC LIMIT 10 [0] []
[2014-03-25 11:39:36] doctrine.DEBUG: SELECT n0_.type AS type0, n0_.body AS body1, n0_.state AS state2, n0_.restart_count AS restart_count3, n0_.created_at AS created_at4, n0_.updated_at AS updated_at5, n0_.started_at AS started_at6, n0_.completed_at AS completed_at7, n0_.id AS id8 FROM notification__message n0_ WHERE n0_.state = ? ORDER BY n0_.created_at ASC LIMIT 10 [0] []
[2014-03-25 11:39:36] doctrine.DEBUG: SELECT n0_.type AS type0, n0_.body AS body1, n0_.state AS state2, n0_.restart_count AS restart_count3, n0_.created_at AS created_at4, n0_.updated_at AS updated_at5, n0_.started_at AS started_at6, n0_.completed_at AS completed_at7, n0_.id AS id8 FROM notification__message n0_ WHERE n0_.state = ? ORDER BY n0_.created_at ASC LIMIT 10 [0] []
[2014-03-25 11:39:37] doctrine.DEBUG: SELECT n0_.type AS type0, n0_.body AS body1, n0_.state AS state2, n0_.restart_count AS restart_count3, n0_.created_at AS created_at4, n0_.updated_at AS updated_at5, n0_.started_at AS started_at6, n0_.completed_at AS completed_at7, n0_.id AS id8 FROM notification__message n0_ WHERE n0_.state = ? ORDER BY n0_.created_at ASC LIMIT 10 [0] []
[2014-03-25 11:39:37] doctrine.DEBUG: SELECT n0_.type AS type0, n0_.body AS body1, n0_.state AS state2, n0_.restart_count AS restart_count3, n0_.created_at AS created_at4, n0_.updated_at AS updated_at5, n0_.started_at AS started_at6, n0_.completed_at AS completed_at7, n0_.id AS id8 FROM notification__message n0_ WHERE n0_.state = ? ORDER BY n0_.created_at ASC LIMIT 10 [0] []
[2014-03-25 11:39:38] doctrine.DEBUG: SELECT n0_.type AS type0, n0_.body AS body1, n0_.state AS state2, n0_.restart_count AS restart_count3, n0_.created_at AS created_at4, n0_.updated_at AS updated_at5, n0_.started_at AS started_at6, n0_.completed_at AS completed_at7, n0_.id AS id8 FROM notification__message n0_ WHERE n0_.state = ? ORDER BY n0_.created_at ASC LIMIT 10 [0] []
[2014-03-25 11:39:38] doctrine.DEBUG: SELECT n0_.type AS type0, n0_.body AS body1, n0_.state AS state2, n0_.restart_count AS restart_count3, n0_.created_at AS created_at4, n0_.updated_at AS updated_at5, n0_.started_at AS started_at6, n0_.completed_at AS completed_at7, n0_.id AS id8 FROM notification__message n0_ WHERE n0_.state = ? ORDER BY n0_.created_at ASC LIMIT 10 [0] []
[2014-03-25 11:39:39] doctrine.DEBUG: SELECT n0_.type AS type0, n0_.body AS body1, n0_.state AS state2, n0_.restart_count AS restart_count3, n0_.created_at AS created_at4, n0_.updated_at AS updated_at5, n0_.started_at AS started_at6, n0_.completed_at AS completed_at7, n0_.id AS id8 FROM notification__message n0_ WHERE n0_.state = ? ORDER BY n0_.created_at ASC LIMIT 10 [0] []
[2014-03-25 11:39:39] doctrine.DEBUG: SELECT n0_.type AS type0, n0_.body AS body1, n0_.state AS state2, n0_.restart_count AS restart_count3, n0_.created_at AS created_at4, n0_.updated_at AS updated_at5, n0_.started_at AS started_at6, n0_.completed_at AS completed_at7, n0_.id AS id8 FROM notification__message n0_ WHERE n0_.state = ? ORDER BY n0_.created_at ASC LIMIT 10 [0] []
[2014-03-25 11:39:40] doctrine.DEBUG: SELECT n0_.type AS type0, n0_.body AS body1, n0_.state AS state2, n0_.restart_count AS restart_count3, n0_.created_at AS created_at4, n0_.updated_at AS updated_at5, n0_.started_at AS started_at6, n0_.completed_at AS completed_at7, n0_.id AS id8 FROM notification__message n0_ WHERE n0_.state = ? ORDER BY n0_.created_at ASC LIMIT 10 [0] []
[2014-03-25 11:39:40] doctrine.DEBUG: SELECT n0_.type AS type0, n0_.body AS body1, n0_.state AS state2, n0_.restart_count AS restart_count3, n0_.created_at AS created_at4, n0_.updated_at AS updated_at5, n0_.started_at AS started_at6, n0_.completed_at AS completed_at7, n0_.id AS id8 FROM notification__message n0_ WHERE n0_.state = ? ORDER BY n0_.created_at ASC LIMIT 10 [0] []

Solution

Hugo below got me going in the right direction. The issue is the way that swift mailer is configured. It spools the message into memory and then sends the message once the kernel terminate event fires, however this event doesn't seem to work with the notification since the kernel never terminates. See this Unable to send e-mail from within custom Symfony2 command but can from elsewhere in app.

To solve this issue I changed the configuration of my swift mailer to the following:

# config.yml Swifmailer configuration.
swiftmailer:
    transport: %mailer_transport%
    host:      %mailer_host%
    username:  %mailer_user%
    password:  %mailer_password%
    spool:     { type: file, path: "%kernel.root_dir%/spool" }
    logging:   %kernel.debug%
    port:      %mailer_port%
    encryption: %mailer_encryption%

Once you have this setup the messages will be written to a file. To send the messages you have to run a command: php app/console swiftmailer:spool:send. For more details on spooling please see: http://symfony.com/doc/current/cookbook/email/spool.html

1

1 Answers

3
votes

Did you launch the notification consumers?

You need to run the command:

php app/console sonata:notification:start; this will consume your notification messages.

Now that is not needed in postpone or runtime modes as those use "in-memory" events. But if you put messages in a stores queue such as Doctrine's, you will need to run a separate process to consume them.

Feel free to check out the SonataNotificationBundle documentation to get some more details (and don't forget to use a monitoring process tool such as Supervisor in your production environment).