From 299ead142565413b81b9926ff45c3f8d866e72d7 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sun, 25 Jan 2015 15:54:19 -0500 Subject: [PATCH 1/3] Quick proofread of the email cookbook --- cookbook/email/email.rst | 87 +++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/cookbook/email/email.rst b/cookbook/email/email.rst index 1d9f42edc47..1d16a67d084 100644 --- a/cookbook/email/email.rst +++ b/cookbook/email/email.rst @@ -7,30 +7,25 @@ How to Send an Email Sending emails is a classic task for any web application and one that has special complications and potential pitfalls. Instead of recreating the wheel, one solution to send emails is to use the SwiftmailerBundle, which leverages -the power of the `Swift Mailer`_ library. - -.. note:: - - Don't forget to enable the bundle in your kernel before using it:: - - public function registerBundles() - { - $bundles = array( - // ... - - new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(), - ); - - // ... - } +the power of the `Swift Mailer`_ library. This bundles comes with the Symfony +Standard Edition. .. _swift-mailer-configuration: Configuration ------------- -Before using Swift Mailer, be sure to include its configuration. The only -mandatory configuration parameter is ``transport``: +To use Swift Mailer, you'll need to configure it for your mail server. + +.. tip:: + + Instead of setting up/using your own mail server, you may want to use + a hosted mail provider such as `Mandrill`_, `SendGrid`_, `Amazon SES`_ + or others. These give you an SMTP server, username and password (sometimes + called keys) that can be used with the Swift Mailer configuration. + +In a standard Symfony installation, some ``swiftmailer`` configuration is +already included: .. configuration-block:: @@ -38,12 +33,10 @@ mandatory configuration parameter is ``transport``: # app/config/config.yml swiftmailer: - transport: smtp - encryption: ssl - auth_mode: login - host: smtp.gmail.com - username: your_username - password: your_password + transport: "%mailer_transport%" + host: "%mailer_host%" + username: "%mailer_user%" + password: "%mailer_password%" .. code-block:: xml @@ -55,27 +48,24 @@ mandatory configuration parameter is ``transport``: --> + transport="%mailer_transport%" + host="%mailer_host%" + username="%mailer_user%" + password="%mailer_password%" /> .. code-block:: php // app/config/config.php $container->loadFromExtension('swiftmailer', array( - 'transport' => "smtp", - 'encryption' => "ssl", - 'auth_mode' => "login", - 'host' => "smtp.gmail.com", - 'username' => "your_username", - 'password' => "your_password", + 'transport' => "%mailer_transport%", + 'host' => "%mailer_host%", + 'username' => "%mailer_user%", + 'password' => "%mailer_password%", )); -The majority of the Swift Mailer configuration deals with how the messages -themselves should be delivered. +These values (e.g. ``%mailer_transport%``), are reading from the parameters +that are set in the :ref:`parameters.yml ` file. You +can modify the values in that file, or set the values directly here. The following configuration attributes are available: @@ -105,15 +95,27 @@ an email is pretty straightforward:: { $mailer = $this->get('mailer'); $message = $mailer->createMessage() - ->setSubject('Hello Email') + ->setSubject('You have Completed Registration!') ->setFrom('send@example.com') ->setTo('recipient@example.com') ->setBody( $this->renderView( - 'HelloBundle:Hello:email.txt.twig', + // app/Resources/views/Emails/registration.html.twig + 'Emails/registration.html.twig', + array('name' => $name) + ), + 'text/html' + ) + /* + * If you also want to include a plaintext version of the message + ->addPart( + $this->renderView( + 'Emails/registration.txt.twig', array('name' => $name) - ) + ), + 'text/plain' ) + */ ; $mailer->send($message); @@ -138,3 +140,6 @@ of `Creating Messages`_ in great detail in its documentation. .. _`Swift Mailer`: http://swiftmailer.org/ .. _`Creating Messages`: http://swiftmailer.org/docs/messages.html +.. _`Mandrill`: https://mandrill.com/ +.. _`SendGrid`: https://sendgrid.com/ +.. _`Amazon SES`: http://aws.amazon.com/ses/ From 5207800f3ddb6dbca7f8857615091d25125d483b Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sun, 25 Jan 2015 16:08:19 -0500 Subject: [PATCH 2/3] Adding reference link --- best_practices/configuration.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/best_practices/configuration.rst b/best_practices/configuration.rst index b29b4a7b778..df9779b121e 100644 --- a/best_practices/configuration.rst +++ b/best_practices/configuration.rst @@ -6,6 +6,8 @@ and security credentials) and different environments (development, production). That's why Symfony recommends that you split the application configuration into three parts. +.. _config-parameters.yml: + Infrastructure-Related Configuration ------------------------------------ From d32c51c3ab11855b28354619d6c56fa05991c0da Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Thu, 29 Jan 2015 21:32:06 -0500 Subject: [PATCH 3/3] Fixing typo thanks to xabbuh --- cookbook/email/email.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookbook/email/email.rst b/cookbook/email/email.rst index 1d16a67d084..4d97ec31b62 100644 --- a/cookbook/email/email.rst +++ b/cookbook/email/email.rst @@ -7,7 +7,7 @@ How to Send an Email Sending emails is a classic task for any web application and one that has special complications and potential pitfalls. Instead of recreating the wheel, one solution to send emails is to use the SwiftmailerBundle, which leverages -the power of the `Swift Mailer`_ library. This bundles comes with the Symfony +the power of the `Swift Mailer`_ library. This bundle comes with the Symfony Standard Edition. .. _swift-mailer-configuration: