Symfony
sponsored by SensioLabs
Menu
  • About
  • Documentation
  • Screencasts
  • Cloud
  • Certification
  • Community
  • Businesses
  • News
  • Download
  1. Home
  2. Documentation
  3. Email
  4. How to Use the Cloud to Send Emails
  • Documentation
  • Book
  • Reference
  • Bundles
  • Cloud
Search by Algolia

How to Use the Cloud to Send Emails

Edit this page

Warning: You are browsing the documentation for Symfony 3.2, which is no longer maintained.

Read the updated version of this page for Symfony 6.2 (the current stable version).

How to Use the Cloud to Send Emails

Requirements for sending emails from a production system differ from your development setup as you don't want to be limited in the number of emails, the sending rate or the sender address. Thus, using Gmail or similar services is not an option. If setting up and maintaining your own reliable mail server causes you a headache there's a simple solution: Leverage the cloud to send your emails.

This article shows how easy it is to integrate Amazon's Simple Email Service (SES) into Symfony.

Note

You can use the same technique for other mail services, as most of the time there is nothing more to it than configuring an SMTP endpoint for Swift Mailer.

In the Symfony configuration, change the Swift Mailer settings transport, host, port and encryption according to the information provided in the SES console. Create your individual SMTP credentials in the SES console and complete the configuration with the provided username and password:

  • YAML
  • XML
  • PHP
1
2
3
4
5
6
7
8
# app/config/config.yml
swiftmailer:
    transport:  smtp
    host:       email-smtp.us-east-1.amazonaws.com
    port:       587 # different ports are available, see SES console
    encryption: tls # TLS encryption is required
    username:   AWS_SES_SMTP_USERNAME  # to be created in the SES console
    password:   AWS_SES_SMTP_PASSWORD  # to be created in the SES console
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!-- app/config/config.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:swiftmailer="http://symfony.com/schema/dic/swiftmailer"
    xsi:schemaLocation="http://symfony.com/schema/dic/services
        http://symfony.com/schema/dic/services/services-1.0.xsd
        http://symfony.com/schema/dic/swiftmailer
        http://symfony.com/schema/dic/swiftmailer/swiftmailer-1.0.xsd">

    <!-- ... -->
    <swiftmailer:config
        transport="smtp"
        host="email-smtp.us-east-1.amazonaws.com"
        port="587"
        encryption="tls"
        username="AWS_SES_SMTP_USERNAME"
        password="AWS_SES_SMTP_PASSWORD"
    />
</container>
1
2
3
4
5
6
7
8
9
// app/config/config.php
$container->loadFromExtension('swiftmailer', array(
    'transport'  => 'smtp',
    'host'       => 'email-smtp.us-east-1.amazonaws.com',
    'port'       => 587,
    'encryption' => 'tls',
    'username'   => 'AWS_SES_SMTP_USERNAME',
    'password'   => 'AWS_SES_SMTP_PASSWORD',
));

The port and encryption keys are not present in the Symfony Standard Edition configuration by default, but you can simply add them as needed.

And that's it, you're ready to start sending emails through the cloud!

Tip

If you are using the Symfony Standard Edition, configure the parameters in parameters.yml and use them in your configuration files. This allows for different Swift Mailer configurations for each installation of your application. For instance, use Gmail during development and the cloud in production.

1
2
3
4
5
6
7
8
9
# app/config/parameters.yml
parameters:
    # ...
    mailer_transport:  smtp
    mailer_host:       email-smtp.us-east-1.amazonaws.com
    mailer_port:       587 # different ports are available, see SES console
    mailer_encryption: tls # TLS encryption is required
    mailer_user:       AWS_SES_SMTP_USERNAME # to be created in the SES console
    mailer_password:   AWS_SES_SMTP_PASSWORD # to be created in the SES console

Note

If you intend to use Amazon SES, please note the following:

  • You have to sign up to Amazon Web Services (AWS);
  • Every sender address used in the From or Return-Path (bounce address) header needs to be confirmed by the owner. You can also confirm an entire domain;
  • Initially you are in a restricted sandbox mode. You need to request production access before being allowed to send to arbitrary recipients;
  • SES may be subject to a charge.
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
We stand with Ukraine.
Version:
Code consumes server resources. Blackfire tells you how

Code consumes server resources. Blackfire tells you how

Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).

Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).

↓ Our footer now uses the colors of the Ukrainian flag because Symfony stands with the people of Ukraine.

Avatar of Eöras, a Symfony contributor

Thanks Eöras for being a Symfony contributor

1 commit • 58 lines changed

View all contributors that help us make Symfony

Become a Symfony contributor

Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

Learn how to contribute

Symfony™ is a trademark of Symfony SAS. All rights reserved.

  • What is Symfony?
    • Symfony at a Glance
    • Symfony Components
    • Case Studies
    • Symfony Releases
    • Security Policy
    • Logo & Screenshots
    • Trademark & Licenses
    • symfony1 Legacy
  • Learn Symfony
    • Symfony Docs
    • Symfony Book
    • Reference
    • Bundles
    • Best Practices
    • Training
    • eLearning Platform
    • Certification
  • Screencasts
    • Learn Symfony
    • Learn PHP
    • Learn JavaScript
    • Learn Drupal
    • Learn RESTful APIs
  • Community
    • SymfonyConnect
    • Support
    • How to be Involved
    • Code of Conduct
    • Events & Meetups
    • Projects using Symfony
    • Downloads Stats
    • Contributors
    • Backers
  • Blog
    • Events & Meetups
    • A week of symfony
    • Case studies
    • Cloud
    • Community
    • Conferences
    • Diversity
    • Documentation
    • Living on the edge
    • Releases
    • Security Advisories
    • SymfonyInsight
    • Twig
    • SensioLabs
  • Services
    • SensioLabs services
    • Train developers
    • Manage your project quality
    • Improve your project performance
    • Host Symfony projects
    Deployed on
Follow Symfony
Search by Algolia