Sonata Notification主义后端邮件未被发送

时间:2014-03-21 16:48:27

标签: symfony sonata-admin symfony-sonata

我有奏鸣曲通知设置,我尝试使用奏鸣曲管理邮件消费者但是当处于教条模式时,通知被消耗但电子邮件根本没有被发送,当我将其设置为推迟或运行时模式邮件确实发送。任何想法都是为什么会这样?

我已经看过这个解决方案(sonataNotificationBundle, emails getting stored to database but swiftmailer consumer is not triggered and no emails are sent),但它与我的问题不同。

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%

两个消费邮件消息的日志文件:

[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] []

解决方案

下面的雨果让我朝着正确的方向前进。问题是swift邮件程序的配置方式。它将消息假脱机到内存中,然后在内核终止事件触发时发送消息,但是这个事件似乎不能用于通知,因为内核永远不会终止。请参阅此Unable to send e-mail from within custom Symfony2 command but can from elsewhere in app

要解决此问题,我将swift邮件程序的配置更改为以下内容:

# 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%

完成此设置后,消息将写入文件。要发送消息,您必须运行命令:php app/console swiftmailer:spool:send。有关假脱机的更多详细信息,请参阅:http://symfony.com/doc/current/cookbook/email/spool.html

1 个答案:

答案 0 :(得分:3)

您是否启动了通知消费者?

您需要运行命令:

php app/console sonata:notification:start;这将消耗您的通知消息。

现在在推迟或运行时模式中不需要这些,因为那些使用" in-memory"事件。但是如果你把消息放在诸如Doctrine的商店队列中,你将需要运行一个单独的进程来使用它们。

请随时查看the SonataNotificationBundle documentation以获取更多详细信息(并且不要忘记在生产环境中使用监控流程工具,例如Supervisor)。