|
| 1 | +.. index:: |
| 2 | + single: Emails; Using the cloud |
| 3 | + |
| 4 | +How to use the Cloud to Send Emails |
| 5 | +=================================== |
| 6 | + |
| 7 | +Requirements for sending emails from a production system differ from your |
| 8 | +development setup as you don't want to be limited in the number of emails, |
| 9 | +the sending rate or the sender address. Thus, |
| 10 | +:doc:`using Gmail </cookbook/email/gmail>`_ or similar services is not an |
| 11 | +option. If setting up and maintaining your own reliable mail server causes |
| 12 | +you a headache there's a simple solution: Leverage the cloud to send your |
| 13 | +emails. |
| 14 | + |
| 15 | +This cookbook shows how easy it is to integrate |
| 16 | +`Amazon's Simple Email Service (SES)`_ into Symfony. |
| 17 | + |
| 18 | +.. note:: |
| 19 | + |
| 20 | + You can use the same technique for other mail services, as most of the |
| 21 | + time there is nothing more to it than configuring an SMTP endpoint for |
| 22 | + Swift Mailer. |
| 23 | + |
| 24 | +In the Symfony configuration, change the Swift Mailer settings ``transport``, |
| 25 | +``host``, ``port`` and ``encryption`` according to the information provided in |
| 26 | +the `SES console`_. Create your individual SMTP credentials in the SES console |
| 27 | +and complete the configuration with the provided ``username`` and ``password``: |
| 28 | + |
| 29 | +.. configuration-block:: |
| 30 | + |
| 31 | + .. code-block:: yaml |
| 32 | +
|
| 33 | + # app/config/config.yml |
| 34 | + swiftmailer: |
| 35 | + transport: smtp |
| 36 | + host: email-smtp.us-east-1.amazonaws.com |
| 37 | + port: 465 # different ports are available, see SES console |
| 38 | + encryption: tls # TLS encryption is required |
| 39 | + username: AWS_ACCESS_KEY # to be created in the SES console |
| 40 | + password: AWS_SECRET_KEY # to be created in the SES console |
| 41 | +
|
| 42 | + .. code-block:: xml |
| 43 | +
|
| 44 | + <!-- app/config/config.xml --> |
| 45 | + <?xml version="1.0" encoding="UTF-8" ?> |
| 46 | + <container xmlns="http://symfony.com/schema/dic/services" |
| 47 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 48 | + xmlns:swiftmailer="http://symfony.com/schema/dic/swiftmailer" |
| 49 | + xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd |
| 50 | + http://symfony.com/schema/dic/swiftmailer http://symfony.com/schema/dic/swiftmailer/swiftmailer-1.0.xsd"> |
| 51 | +
|
| 52 | + <!-- ... --> |
| 53 | + <swiftmailer:config |
| 54 | + transport="smtp" |
| 55 | + host="email-smtp.us-east-1.amazonaws.com" |
| 56 | + port="465" |
| 57 | + encryption="tls" |
| 58 | + username="AWS_ACCESS_KEY" |
| 59 | + password="AWS_SECRET_KEY" |
| 60 | + /> |
| 61 | + </container> |
| 62 | +
|
| 63 | + .. code-block:: php |
| 64 | +
|
| 65 | + // app/config/config.php |
| 66 | + $container->loadFromExtension('swiftmailer', array( |
| 67 | + 'transport' => 'smtp', |
| 68 | + 'host' => 'email-smtp.us-east-1.amazonaws.com', |
| 69 | + 'port' => 465, |
| 70 | + 'encryption' => 'tls', |
| 71 | + 'username' => 'AWS_ACCESS_KEY', |
| 72 | + 'password' => 'AWS_SECRET_KEY', |
| 73 | + )); |
| 74 | +
|
| 75 | +The ``port`` and ``encryption`` keys are not present in the Symfony Standard |
| 76 | +Edition configuration by default, but you can simply add them as needed. |
| 77 | + |
| 78 | +And that's it, you're ready to start sending emails through the cloud! |
| 79 | + |
| 80 | +.. tip:: |
| 81 | + |
| 82 | + If you are using the Symfony Standard Edition, configure the parameters in |
| 83 | + ``parameters.yml`` and use them in your configuration files. This allows |
| 84 | + for different Swift Mailer configurations for each installation of your |
| 85 | + application. For instance, use Gmail during development and the cloud in |
| 86 | + production. |
| 87 | + |
| 88 | + .. code-block:: yaml |
| 89 | +
|
| 90 | + # app/config/parameters.yml |
| 91 | + parameters: |
| 92 | + # ... |
| 93 | + mailer_transport: smtp |
| 94 | + mailer_host: email-smtp.us-east-1.amazonaws.com |
| 95 | + mailer_port: 465 # different ports are available, see SES console |
| 96 | + mailer_encryption: tls # TLS encryption is required |
| 97 | + mailer_user: AWS_ACCESS_KEY # to be created in the SES console |
| 98 | + mailer_password: AWS_SECRET_KEY # to be created in the SES console |
| 99 | +
|
| 100 | +.. note:: |
| 101 | + |
| 102 | + If you intend to use Amazon SES, please note the following: |
| 103 | + |
| 104 | + * You have to sign up to `Amazon Web Services (AWS)`_; |
| 105 | + |
| 106 | + * Every sender address used in the ``From`` or ``Return-Path`` (bounce |
| 107 | + address) header needs to be confirmed by the owner. You can also |
| 108 | + confirm an entire domain; |
| 109 | + |
| 110 | + * Initially you are in a restricted sandbox mode. You need to request |
| 111 | + production access before being allowed to send to arbitrary |
| 112 | + recipients; |
| 113 | + |
| 114 | + * SES may be subject to a charge. |
| 115 | + |
| 116 | +.. _`Amazon's Simple Email Service (SES)`: http://aws.amazon.com/ses |
| 117 | +.. _`SES console`: https://console.aws.amazon.com/ses |
| 118 | +.. _`Amazon Web Services (AWS)`: http://aws.amazon.com |
0 commit comments