-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi key and domain #38
Comments
I do not think that is supported. That should be an excellent feature. |
it 's possible to move the api key to the file config in param in the mailer class ? |
I'm not too sure what you mean. I think we should allow config like: Mailgun:
foo:
Key: xx
Domain: xx
Bar:
Key: yay
Domain: yay |
why not.But this don't working actually ? |
Can't believe this hasn't been implemented, this is actually a show stopper for us. Our CRM platform hosts multiple sites from the same setup, we need the ability to support multiple domains. sigh time to have a dig around in the code. |
Mailgun itself does in fact support multiple domains per account. If they are managed in the same account it should perfectly be possible to use them. |
Actually, there's a very simple solution - subclass the Transport class! Symfony allows you to specify any service as a transport in the config, doing this allows you to inject other dependencies into the transport constructor, allowing you to change the domain passed through to the underlying Mailgun Transport. If anyone is interested... Step 1, create a custom class (customMailgunTransport.php) - I saved this into src/BundleName/SwiftMailer
Then create the new service entry in services.yml...
Alter the mail config - in our case we want the mailgun transport to be manually selected in the code...
Then when you want to send via mailgun, you create it with a call like:
The service name is swiftmailer.mailer. and then the mailer name from the config.yml file. HTH.... |
it' no possible to override the getConfigTreeBuilder with the information in the DB table ? |
You cannot (or should not) access your database at the time when you build your container. That means you have to redeploy every time you get a new customer. What you should do is to create a factory that spits out a new instance of the client each time you call it. That factory itself should check with your database values. |
it's no possible to override cspooSwiftmailerMailgunExtension ? and inject in the val with my database ? |
@fyher - If you take the approach I posted above, you can do what you want to do. You'd load the config in the constructor of the customMailgunTransport class. |
|
hi i have success :) `<?php namespace AdminBundle\SwiftMailer; use cspoo\Swiftmailer\MailgunBundle\Service\MailgunTransport; class CustomMailgunTransport extends MailgunTransport
}`
the service and in the controller for example: `$m=$this->get("swiftmailer.mailer");
in the log of mailgun, I have the email send with domaine B , you can change domaineC etc.. it's work |
Whilst it may work, I'd refactor this so you're not calling the parent's constructor method, perhaps move that functionality into a method called 'init' or something. But glad to see it worked out :) 👍 |
Actually, there's another way to do this without subclassing the Transport class. When the transport sends the message it checks the headers of the email to see if there is a mailgun domain tag there, if there is it uses it. So, either set the header each time you create a message, or better still, use a SwiftPlugin to do it for you. Services.yml:
Note, you'll probably only need one tag, for the default, but we're using mailgun along side other transports, so you need to specify which mailers to attach the plugin to. domainSetterPlugin.php
And that should be it! It does rely on your senders being from domains you've got setup in mailgun however, so if this is not the case, this won't work for you as you'll get invalid domains. Hopefully it may help you either as-is or as inspiration! |
I prefer to set it dynamically for every message like this:
Hope that helps. |
How I can use , if I want multi domain and key ?
thanks
The text was updated successfully, but these errors were encountered: