Symfony2 Monolog to Email Errors why swiftmailer.transport.real is non-existent service
Asked Answered
A

2

6

after updating symfony from 2.3 to 2.4 i got ServiceNotFoundException

 Fatal error: Uncaught exception 'Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException' with message 'The service "monolog.handler.mojhandler" has a dependency on a non-existent service "swiftmailer.transport.real".' in E:\wamp\www\project\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass.php on line 59

here is my config_prod.yml

imports:
    - { resource: config.yml }
monolog:
    handlers:
        main:
            type:         fingers_crossed
            action_level: error
            handler:      streamed
        streamed:
            type:  stream
            path:  %kernel.logs_dir%/%kernel.environment%.log
            level: debug
        mail:
            type:         fingers_crossed
            action_level: error
            handler:      buffered
            channels: ["!app"] # Dont log app because we dont' want 404 errors sending
        buffered:
            type:    buffer
            handler: mojhandler
        mojhandler:
            type:       swift_mailer
            from_email: %mojhandler_logger_email%
            to_email:   %mojhandler_logger_email%
            subject:    "[Panel] An Error Occurred!"
            level:      debug

and here is my swiftmailer configuration from config.yml

# Swiftmailer Configuration
swiftmailer:
    transport: %mailer_transport%
    host:      %mailer_host%
    username:  %mailer_user%
    password:  %mailer_password%
    port:      %mailer_port%
    auth_mode: %mailer_auth_mode%
    encryption: %mailer_encryption%

how can i fix it?

Azimuth answered 12/1, 2014 at 12:45 Comment(3)
Can you try an app/console container:debug --env=prod | grep mail and check the output? You should see all services that are defined and contain the word mail.Sada
here you go: pastebin.com/GVKwv9ct, btw command is only available in degub modeAzimuth
That's weird. What's the value of your %mailer_transport% variable?Sada
P
3

It appears to be an error when upgrading to Monolog Bundle 2.5.0 that causes this if you do not have the 'spool' config value set under the swiftmailer configuration.

Previous answered 20/1, 2014 at 19:58 Comment(1)
it's a correct answer, i manage to fix it long before you answered. hope it will help others!Azimuth
D
7

It seems indeed to be a bug if we dont set the 'spool' config value in the swiftmailer config.

To solve this I had to create the missing services myself (since I don't want to use spool) in one of my services.yml:

swiftmailer.transport.simplemailinvoker:
    class: Swift_Transport_SimpleMailInvoker

swiftmailer.transport.eventdispatcher:
    class: Swift_Events_SimpleEventDispatcher

swiftmailer.transport.real:
    class: Swift_Transport_MailTransport
    arguments: [@swiftmailer.transport.simplemailinvoker, @swiftmailer.transport.eventdispatcher]
Drop answered 23/1, 2014 at 9:3 Comment(0)
P
3

It appears to be an error when upgrading to Monolog Bundle 2.5.0 that causes this if you do not have the 'spool' config value set under the swiftmailer configuration.

Previous answered 20/1, 2014 at 19:58 Comment(1)
it's a correct answer, i manage to fix it long before you answered. hope it will help others!Azimuth

© 2022 - 2024 — McMap. All rights reserved.