swiftmailer-mailgun-bundle icon indicating copy to clipboard operation
swiftmailer-mailgun-bundle copied to clipboard

How to configure this bundle in Symfony 4?

Open Jeeppler opened this issue 5 years ago • 7 comments

Could you provide some information in the README.md on how to configure this bundle in Symfony 4?

Until now I run into the same issue as others have:

However, I think the easiest solution for most of those problems would probably be to add an example configuration for Symfony 4 in the README.md.

Jeeppler avatar Oct 09 '18 18:10 Jeeppler

Hi @Jeeppler, Setting up this on Symfony 4 is slight different.

  1. Add you Mailgun credentials on .env.dist (add the same lines on .env, just in case)
MAILGUN_DOMAIN=<your domain>
MAILGUN_API_KEY=<your key>
MAILGUN_SENDER=<your sender>

  1. Adding on AppKernel, now config/bundles.php cspoo\Swiftmailer\MailgunBundle\cspooSwiftmailerMailgunBundle::class => ['all' => true],

  2. Configuring credentials: Create a new config file on config/packages/mailgun.yaml (if it's not there) and copy the following lines:

cspoo_swiftmailer_mailgun:
    key: '%env(MAILGUN_API_KEY)%'
    domain: "%env(MAILGUN_DOMAIN)%"

services:
    Mailgun\Mailgun:
        class: Mailgun\Mailgun
        factory: ['Mailgun\Mailgun', create]
        arguments: ['%env(MAILGUN_API_KEY)%']
  1. Add the following line on config/packages/swiftmailer:
swiftmailer:
    # url: '%env(MAILER_URL)%'
    transport: 'mailgun'
    spool: { type: 'memory' }

p.s.: Not sure if you really have to comment url

  1. Test your setup with the following command on your terminal: bin/console swiftmailer:email:send --from=<from email> --to=<to email> --subject="Foo" --body="Bar"

With this setup, I've made it work. Let me know if I miss something on it.

Felipe

fluchi avatar Oct 10 '18 12:10 fluchi

@fluchi thank you. Awesome. Do you want add your explanation to the README.md (create pull request)?

Jeeppler avatar Oct 10 '18 16:10 Jeeppler

@fluchi I'm not sure about my situation, but after I installed the bundle. In my config directory, it just add mailgun.yaml. I can't find any find like swiftmailer.yaml or swiftmail.* .So my site is crashing now. Not sure what to do

PhongNguyen512 avatar Nov 09 '18 20:11 PhongNguyen512

@PhongNguyen512, try to create those files manually. On my case, they weren't create via composer due to permission issues (if I'm non mistaken). Then I've create them manually and everything works fine.

fluchi avatar Nov 10 '18 21:11 fluchi

@fluchi Before I posted my question, I also tried to create swiftmailer.yaml file in config/packages. But I got another error There is no extension able to load the configuration for "swiftmailer" (in /home/vagrant/code/project1/config/packages/swiftmailer.yaml). Looked for namespace "swiftmailer", found "framework", "web_profiler", "twig", "monolog", "debug", "sensio_framework_extra", "security", "doctrine_cache", "do ctrine", "doctrine_migrations", "maker", "cspoo_swiftmailer_mailgun"

I also check in vendor/ . I saw cspoo, swiftmailer and mailgun directories in there. I'm not sure where did I go wrong.

PhongNguyen512 avatar Nov 11 '18 19:11 PhongNguyen512

p.s.: Not sure if you really have to comment url

If MAILER_URL is equal to null://localhost then it will definitely interfere.

infomaniac50 avatar Feb 07 '19 04:02 infomaniac50

@infomaniac50 I already solved this issue. In my case, I install swiftmailer first I install this bundle. I think the swiftmailer in this bundle does not exist. Therefore, I install swiftmailer first and it works perfectly.

PhongNguyen512 avatar Feb 11 '19 00:02 PhongNguyen512