symfony / swiftmailer-bundle Goto Github PK
View Code? Open in Web Editor NEWSymfony Swiftmailer Bundle
Home Page: https://symfony.com/swiftmailer-bundle
License: MIT License
Symfony Swiftmailer Bundle
Home Page: https://symfony.com/swiftmailer-bundle
License: MIT License
By default, the mailer will use the 'default' value for the mailer option.
->addOption('mailer', null, InputOption::VALUE_REQUIRED, 'The mailer name', 'default')
When executing swiftmailer: email: send , i was not prompt to enter/confirm/validate my 'mailer', and hence the command was throwing an error :
PHP Fatal error: Call to undefined method Symfony\Bundle\SwiftmailerBundle\Command\NewEmailCommand::getOption() in /Users/ZCJ/Sites/Spade/vendor/symfony/swiftmailer-bundle/Command/NewEmailCommand.php on line 61
That was because my mail service was configured as "gmail" and an exception was being raised in:
$mailerServiceName = sprintf('swiftmailer.mailer.%s', $input->getOption('mailer'));
if (!$this->getContainer()->has($mailerServiceName)) {
throw new \InvalidArgumentException(sprintf('The mailer "%s" does not exist', $this->getOption('mailer')));
}
I think it would be great if we can handle the mailer in the interact dialog.
For that, I am proposing something minor like :
if('default' === $input->getOption('mailer')){
$input->setOption('mailer',$dialog->ask($output, sprintf('Mailer (Enter for 'default'): '),'default'));
}
It would be nice if I could configure more than one delivery address.
My idea is to add another config value:
swiftmailer:
delivery_addresses: ["[email protected]", "[email protected]"]
The sendmail transport uses a UNIX command to send mails. The default command is /usr/sbin/sendmail -bs
. There is currently no way to modify it through the bundle configuration.
Sometime it's necessary to have more than one mailer service. For example, one with spool to send newsletters. And another one without spool to send quick messages, like a contact form.
swiftmailer:
quick:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
queue:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
spool:
type: file
path: /path/to/spool
As of the 'mailers' feature came in, the memory spooling has stopped working.
I found out that the 'mailer' service became just an alias, and that's what is causing the problem.
The 'initialized' method of the Symfony\Component\DependencyInjection\Container does not handle aliases (as it is in the ContainerBuilder), but therefore the EmailSenderListener never sends emails.
I don't really know which is better: if it the Container should handle aliases or the EmailSenderListener should check services in a different way. Anyway, I've made a pull request here which resolves the service checking.
in command class I wrote like:
class checkDateCommand extends ContainerAwareCommand
{
protected function configure()
{
// code......
protected function execute(InputInterface $input, OutputInterface $output)
{
$message = \Swift_Message::newInstance()
->setSubject('subject')
->setFrom('[email protected]')
->setTo('[email protected]')
->setBody('some text');
$this->getContainer()->get('mailer')->send($message);
}
When execute the command, it dosen't send the email to destination address, but these codes work perfectly in controller, whats wrong?!! please help
Swiftmailer supports throttling emails on a per minute basis, but the SF spool commands only support limiting the total emails or the time for command execution. Would it be possible to add this feature?
I found out that when I deploy my application for the first time on production that the settings for the SMTP are incorrect, the way I have to find it out is to run a controller that mails.
Now I was thinking that it would be handy if there will be a console command for swiftmailer that checks if the settings are correct and sends a test mail.
What do you guys thinking about that?
It would be absolutely great if it was possible to type in e.g. app/console swiftmailer:spool:display
and get a list of emails that are currently in the spool (if spool type is file
) - that would make debugging and development easier
or support customized spool.
There is a known security in swiftmailer/swiftmailer < 5.2.1 (http://blog.swiftmailer.org/post/88660759928/security-fix-swiftmailer-5-2-1-released).
The composer file should allow to update up to 5.2.1 instead of 5.0.*
I have a command that sends emails. When I set spool to memory and try to send the email it does not send.
If I change the type to file and then run the swiftmailer:spool:send it sends it.
This seems to be related to console because if I run the exact same function in browser the email is delivered via spool.
Perhaps something to do with the Terminate Event not being called in console?
new error
[2014-05-28 21:00:06] event.DEBUG: Notified event "console.terminate" to listener "Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener::onTerminate". [] []
i just updated and got this, was working fine before
In bab1b1d the template was changed to convert the message body to UTF-8. This fails with an exception (ErrorException: Warning: mb_convert_encoding(): Illegal character encoding specified
) when message.charset
is null, as is the case with some multipart messages.
<pre>{{ message.body|e('html', message.charset)|convert_encoding('UTF-8', message.charset) }}</pre>
The getCharset method returns the charset
field in the message's Content-Type
header. For multipart messages it will not normally be set . (The extra header field may not have been cleaned up yet depending on the order that the parts were added.) I wasn't able to find any good way to get the charset of the body part, so perhaps this is also an issue with SwiftMailer. In any even if the charset cannot be determined the profiler should either assume UTF-8 or display an error message.
The SwiftmailerBundle should allow to configure FailoverTransport or LoadBalancedTransport without doing it manually or using a compiler pass. Both of these transports work in a way that they can take various sub-transports and either do round-robin or failover.
Hi There,
I want to send a massa email to my costumers.
I have to next code:
foreach( $emailContacts AS $contact ){
$message = \Swift_Message::newInstance()
->setSubject( $email['subject'] )
->setFrom( $this->get( 'config' )->getKey( 'email' ) )
->setTo( $contact->getEmail() )
->setBody($this->renderView('MVCaravanBundle:MailTemplates:blank.html.twig',array(
'body' => nl2br( $body ),
'signature' => $signature
)), 'text/html');
$this->get('mailer')->send($message);
}
He should mail over 200 contacts, smtp is right because on a other page I can send mails.
What is wrong and what schould/can i do?
Thnx
Expected response code 250 but got code "554", with message "554 Too many nonmail commands
"
500 Internal Server Error - Swift_TransportException
Is it possible to allow 5.1.0 verison of swiftmailer
to be used with this bundle ?
Thanks.
Hello;
Apologies if this is an easy one, but I have been looking in the documentation and googling and I couldn't find anything on these lines.
Is there any way to configure swiftmailer so that it includes the attachments on the spooled messages?
I am planning to move the spooled messages to another server to be processed and this machine will not have access to the attachments on their original locations.
If this is not implemented, please consider adding this feature.
Thanks a lot in advance.
Sending just one email takes too long on a server (and keeps the page loading) compared to the dev server and local machine:
On the dev server and local machine it works instantly, but on the issue server it takes at least 2 minutes (and the browser still waits for the response - continuously loads).
Shouldn't the kernel.terminate: Typical Purposes: To perform some "heavy" action after the response has been streamed to the user
It seems as a server issue but can't figure out why:
The transport of the email is smtp and is configured correctly as in the end I receive the email. It is using spool: { type: memory }.
From the profiler timeline: the kernel.terminate and EmailSenderListener take the same amount of time (more than 2 minutes).
Using Symfony 2.1.11.
I am trying to use two different mailers from my console command. The problem is that the username / password seems to be overwritten. I checked on #symfony IRC where I was told that they apparently share the same auth handler.
I wrote a MailHandler with this service config:
mailhandler:
class: %mailhandler.class%
arguments: [@logger, @swiftmailer.mailer.local_mailer, @swiftmailer.mailer.sendgrid_mailer]
My swiftmailer config is as follows:
swiftmailer:
default_mailer: local_mailer
mailers:
sendgrid_mailer:
transport: smtp
host: smtp.sendgrid.net
port: 587
encryption: ~
username: xxx
password: xxx
antiflood:
threshold: 99
sleep: 2
local_mailer:
transport: smtp
host: 127.0.0.1
port: 587
encryption: ~
username: null
password: null
antiflood:
threshold: 99
sleep: 2
Now when I log some stuff in my MailHandler:
public function __construct($logger, $measureMailer, $sendGridMailer) {
$this->logger = $logger;
$this->measureMailer = $measureMailer;
$this->logger->debug("Measuremail host: ".$this->measureMailer->getTransport()->getHost()." user: ".$this->measureMailer->getTransport()->getUsername());
$this->sendGridMailer = $sendGridMailer;
$this->logger->debug("Sendgrid host: ".$this->sendGridMailer->getTransport()->getHost()." user: ".$this->sendGridMailer->getTransport()->getUsername());
echo "var dump";
var_dump($this->measureMailer->getTransport()->getUsername() === $this->sendGridMailer->getTransport()->getUsername());
}
It seems that the username / password is always the one from the last mailer. The host names do differ though, having 127.0.0.1 and smtp.sendgrid.net as their values.
Also note that the code is being executed from a console script that extends from ContainerAwareCommand. When I test this in a normal controller, I don't have any issues. The username/password are different then (as they should).
By testing in a normal controller, I mean a controller that handles a HTTP request.. I wrote this little test:
/**
* @Route("/mail", name="_test_mail")
*/
public function mailAction() {
$mailer = $this->container->get('swiftmailer.mailer.sendgrid_mailer');
echo "Sendgrid user: ".$mailer->getTransport()->getUsername();
$mailer = $this->container->get('swiftmailer.mailer.local_mailer');
echo "Local user: ".$mailer->getTransport()->getUsername();
return new Response("Nou doei");
}
The SMTP transport has two additional options that should be configurable via the bundle configuration. First ist timeout
which is an integer value and should call setTimeout
and second is source_ip
, which should be used to call setSourceIp
.
I updated the composer.json recently, but I got following error:
ErrorException: Warning: call_user_func() expects parameter 1 to be a valid callback, function 'vendor/swiftmailer/swiftmailer/lib/swift_init.php' not found or invalid function name in vendor\swiftmailer\swiftmailer\lib\classes\Swift.php line 67
dunno how to solve this problem. Here are the composer fragment:
"symfony/symfony": "2.1.*",
"symfony/swiftmailer-bundle": "dev-master",
any help?
I have some event listeners registered via
<service id="swiftmailer.transport.eventdispatcher"
class="Swift_Events_SimpleEventDispatcher" public="false">
<call method="bindEventListener">
<argument type="service" id="myListener" />
</call>
<!-- some more -->
</service>
which aren't invoked anymore. It seems that commit 69d6c36 (which merged #34) is causing this. Is such a break intended? I don't see a changelog or upgrade guide.
With Swiftmailer, when an email is sent, the default behaviour is to spool it in memory and then do the actual send during the kernel.terminate
event.
In https://github.com/symfony/SwiftmailerBundle/blob/master/EventListener/EmailSenderListener.php, if the $spool->flushQueue()
method (line 50) raises an exception (such as the SMTP server is down or the credentials don't work) it's just ignored. I don't see it in the logs or get any kind of notification.
I figured that the easiest way around this is to do something like:
try {
$spool->flushQueue($this->container->get(sprintf('swiftmailer.mailer.%s.transport.real', $name)));
} catch (\Swift_TransportException $ex) {
$this->container->get('logger')->critical($ex->getMessage());
}
but I don't know enough about the Kernel to know if this will have any strange side effects.
Is this a good idea?
Im not sure if the problem is with Swiftmailer or the Security component.
There is a bug at the moment, where: you cannot spool an email and authenticate the user in the same response.
The authentication works, but the session disappears for One request, before appearing again. This only happens when the email is actually sent.
This causes the user to appear 'Anonymous' for the next response, which is causing problems, as the application could be expecting the user to be logged in.
This currently prevents spooling emails on any events where the user may also get logged in,
password change success
email confirmation
account created
etc
I have created a test bundle using symfony standard and the demo login setup.
https://github.com/carlcraig/symfony-standard/tree/spool-auth
I have also tested this with FOSUserBundle
https://github.com/carlcraig/symfony-standard/tree/fos-userbundle-spool-auth
Has anyone else encountered this problem?
Is there any way to get round this?
Additional information:
I can show the email in the provider but it was never received. I try with mail and smtp transport and same issue.
It would be really amazing if it was possible to specify e.g. "default_from_email" in config.yml that SwiftmailerBundle would use whenever no sender email was specified
The use case would be if some mails are kinda urgent/high priority (and then would be sent either directly or by the memory spool) but others have a low priority and should not affect the users' experience (and thus rather be sent by a cron job flushing a file spool).
I imagine it would allow other use cases including plugins specific things...
What do you think? What I'm thinking about is the kind of thing DoctrineBundle does with its configuration (allowing to define several connections/managers but also a default one with simpler config).
Hello
I have this error :
FatalErrorException: Error: Class 'Symfony\Component\Console\ConsoleEvents' not found in \vendor\symfony\swiftmailer-bundle\Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener.php line 62
Here is my composer :
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.2.*",
"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "1.2.*",
"twig/extensions": "1.0.*",
"symfony/assetic-bundle": "2.1.*",
"symfony/swiftmailer-bundle": "2.2.*",
"symfony/monolog-bundle": "2.2.*",
"sensio/distribution-bundle": "2.2.*",
"sensio/framework-extra-bundle": "2.2.*",
"sensio/generator-bundle": "2.2.*",
"jms/security-extra-bundle": "1.4.*",
"jms/di-extra-bundle": "1.3.*",
"friendsofsymfony/user-bundle": "*",
"jms/serializer-bundle":"dev-master",
"friendsofsymfony/rest-bundle":"dev-master",
"doctrine/doctrine-fixtures-bundle": "dev-master",
"escapestudios/wsse-authentication-bundle": "2.2.x-dev",
"hwi/oauth-bundle": "0.3.*@dev",
"richsage/rms-push-notifications-bundle": "dev-master"
But with
"symfony/symfony": "2.2.9",
"symfony/swiftmailer-bundle": "2.2.6",
it works
#34 merged, but documentation wasn't updated http://symfony.com/doc/master/reference/configuration/swiftmailer.html
Setting swiftmailer up with the memory spooling does not work as the kernel seems to never terminate so the onKernelTerminate is never triggered.
I experienced this with the standard setup of symfony 2.1 (the configuration files are from RC1) where none of my emails sent through a command got sent. Removing the spooling options from my configuration, emailing went fine.
I don't know if it's possible to change the console to terminate the kernel so the emails get sent. This would of course be best.
If this is not possible, maybe the documentation should state this and offer ways to work around this.
This happens when running unit tests, with phpunit bootstrap containing calls to autoloader.
PHP Fatal error: Cannot redeclare _swiftmailer_init() (previously declared in /var/www/dennis/vendor/swiftmailer/swiftmailer/lib/swift_required.php:24) in /var/www/dennis/vendor/swiftmailer/swiftmailer/lib/swift_required.php on line 27
swift_required.php contains a check for
if (defined('SWIFT_REQUIRED_LOADED')) {,
but including this file causes a fatal error, before this check is executed.
if this is added to /vendor/autoload.php, then it works
if (! defined('SWIFT_REQUIRED_LOADED')) {
require __DIR__ . '/swiftmailer/swiftmailer/lib/swift_required.php';
}
When you have the "spool email" feature enabled in your Symfony2 project, you can not send "normal" mails in the moment.
Would be a good option a parameter to sent the email in the moment, although the "spool feature" was enabled.
for example: $this->get('mailer')->send($message,false); // second parameter to disable spool feature
If I have 2 mailers configured they both share the same instance of Swift_Transport_Esmtp_AuthHandler
This means that if I request the 1st mailer from the container, then request the second mailer, then try to send an email with the 1st, it has the wrong username and password credentials.
Suggested fix is to make "swiftmailer.transport.authhandler" prototype scope
I'm running:
symfony 2.2.-dev
symfony/swiftmailer-bundle dev-master f5e5d12 (v. 2.3.4)
Once I set
swiftmailer:
disable_delivery: false
I get these errors:
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
Unable to replace alias "smtpd" with "swiftmailer.mailer.default.transport.real".
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
The service definition "smtpd" does not exist.
if I replace my "transport" with "gmail", I get the same error but with "gmaild".
Thanks,
Marco
In my config_dev.yml:
swiftmailer:
delivery_address: %swiftmailer.delivery_address%
In the SwiftmailerExtension.php I dump the container to check if the config has been set.
And I saw my own delivery_address.
But he still sends the mail to the address that I give in the controller.
How to fix this?
I'm testing on debian 7, php 5.5, symfony 2.3.1
With the FOSUserBundle, for the validation by email, all email sent on a same email (caching problem ? ). The paramaters passed to Swifmailer seems good but don't used.
I tested without FOSUserBunble, sending email with swiftmailer, same problem, it doesn't use the recipient's email, it seem to use a email on cache (this is a email used one time).
I'm sending with the mail() function and I don't have problem.
Can you please help me ?
PHP Fatal error: require(): Failed opening required '/project/vendor/symfony/swiftmailer-bundle/Symfony/Bundle/SwiftmailerBundle/SwiftmailerBundle.php' (include_path='.:/usr/share/php:/usr/share/pear') in /project/app/bootstrap.php.cache on line 2730" while reading response header from upstream
I see that there has been a huge change in this bundle for 2.3.3. SncRedisBundle spooling registered a service named "swiftmailer.spool.redis" which was then used by this bundle. But from 2.3.3 (specifically this commit cf5de43) the service has to be named "swiftmailer.mailer.redis.spool.{something}".
Why this BC break? BC compatibility was supposed to be one of the main goals of 2.3. Switching back to 2.3.2 for the time being.
Ping @snc
It seems to be a problem with composer.json requirements. Here is the php composer.phar install
output:
- Installation request for swiftmailer/swiftmailer == 4.1.8.0 -> satisfiable by swiftmailer/swiftmailer v4.1.8.
- symfony/swiftmailer-bundle dev-master requires swiftmailer/swiftmailer >=4.2-dev -> satisfiable by swiftmailer/swiftmailer dev-master, swiftmailer/swiftmailer 4.2.x-dev, swiftmailer/swiftmailer v4.2.0.
- Can only install one of: swiftmailer/swiftmailer v4.1.8, swiftmailer/swiftmailer dev-master.
- Can only install one of: swiftmailer/swiftmailer v4.1.8, swiftmailer/swiftmailer 4.2.x-dev.
- Can only install one of: swiftmailer/swiftmailer v4.2.0, swiftmailer/swiftmailer v4.1.8.
- Installation request for symfony/swiftmailer-bundle == 9999999-dev -> satisfiable by symfony/swiftmailer-bundle dev-master.
What about using >=4.2.x-dev
or dev-master
instead of >=4.2-dev
?
Thanks.
It would be nice, if one can configure one connection with a single string (URI, ...) instead of multiple separate configuration keys
smtp://user:pass@host
In the WebProfiler, it would be nice to render the resulting HTML of spooled emails of type "text/html" (with a button that opens a popup for instance...)
I'm using the spool command on a windows machine.
the following command forces me to re-build the cache
php app/console swiftmailer:spool:send --env=prod
but this works
php app/console swiftmailer:spool:send --env=prod --no-debug
In my apache error_log:
[Wed Sep 12 15:53:09 2012] [error] [client ] PHP Fatal error: Class 'EM505093a7cf22b546a8d2\CG_\Doctrine\ORM\EntityManager' not found in D:\wwwroot\example.com\app\cache\prod\appProdProjectContainer.php on line 115
This happens when I use it with AWS and For Loop to send emails. I don't use spool.
I was wondering if there is any interest in a command which monitors the spooling queue, giving information about the number of items in the queue, the date of the item longest in the queue and so on.
Background: I would like to monitor my queue with Icinga and while writing a shell script solves this issue for now, having a command could be handy:
I could implement this if there is interest in merging it back.
Hello,
I'm making some symfony commands witch send mails and test them.
The process in command is the following (see the symfony documentation here: http://symfony.com/doc/current/cookbook/console/sending_emails.html ):
$mailer = $container->get('mailer');
// Log each message "sent"
$mailer->send($message);
// now manually flush the queue
$spool = $mailer->getTransport()->getSpool();
$transport = $container->get('swiftmailer.transport.real');
// Re-log the message
$spool->flushQueue($transport);
The result of this operation is obvious, if you send 2 messages, the logger will tell you that you sent 4.
Is it a willing feature or a real bug ? Because it's really weird.
I'm trying to send email to this example address: tomáš[email protected]
which is ok under RFC6531 standard and it passes through form validation using this code:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add(
'email',
'text',
array(
'constraints' => array(
new NotBlank(),
new Email(
array(
'strict' => true,
'checkMX' => true,
'checkHost' => true
)
),
),
)
)
however, I'm getting this error:
[Swift_RfcComplianceException]
Address in mailbox given [tomáš[email protected]] does not comply with RFC 2822, 3.6.2.
is it a problem in swiftmailer bundle or SMTP server? if it is in the bundle, how can I change the RFC standard to make this work? thank you for help
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.