|
1 | 1 | .. index:: |
2 | | - single: Console; Sending emails |
3 | 2 | single: Console; Generating URLs |
4 | 3 |
|
5 | | -How to Generate URLs and Send Emails from the Console |
6 | | -===================================================== |
| 4 | +How to Generate URLs from the Console |
| 5 | +===================================== |
7 | 6 |
|
8 | 7 | Unfortunately, the command line context does not know about your VirtualHost |
9 | 8 | or domain name. This means that if you generate absolute URLs within a |
@@ -84,43 +83,3 @@ from the ``router`` service and override its settings:: |
84 | 83 | // ... your code here |
85 | 84 | } |
86 | 85 | } |
87 | | - |
88 | | -Using Memory Spooling |
89 | | ---------------------- |
90 | | - |
91 | | -.. versionadded:: 2.3 |
92 | | - When using Symfony 2.3+ and SwiftmailerBundle 2.3.5+, the memory spool is now |
93 | | - handled automatically in the CLI and the code below is not necessary anymore. |
94 | | - |
95 | | -Sending emails in a console command works the same way as described in the |
96 | | -:doc:`/cookbook/email/email` cookbook except if memory spooling is used. |
97 | | - |
98 | | -When using memory spooling (see the :doc:`/cookbook/email/spool` cookbook for more |
99 | | -information), you must be aware that because of how Symfony handles console |
100 | | -commands, emails are not sent automatically. You must take care of flushing |
101 | | -the queue yourself. Use the following code to send emails inside your |
102 | | -console command:: |
103 | | - |
104 | | - $message = new \Swift_Message(); |
105 | | - |
106 | | - // ... prepare the message |
107 | | - |
108 | | - $container = $this->getContainer(); |
109 | | - $mailer = $container->get('mailer'); |
110 | | - |
111 | | - $mailer->send($message); |
112 | | - |
113 | | - // now manually flush the queue |
114 | | - $spool = $mailer->getTransport()->getSpool(); |
115 | | - $transport = $container->get('swiftmailer.transport.real'); |
116 | | - |
117 | | - $spool->flushQueue($transport); |
118 | | - |
119 | | -Another option is to create an environment which is only used by console |
120 | | -commands and uses a different spooling method. |
121 | | - |
122 | | -.. note:: |
123 | | - |
124 | | - Taking care of the spooling is only needed when memory spooling is used. |
125 | | - If you are using file spooling (or no spooling at all), there is no need |
126 | | - to flush the queue manually within the command. |
0 commit comments