Skip to content
  • About
    • What is Symfony?
    • Community
    • News
    • Contributing
    • Support
  • Documentation
    • Symfony Docs
    • Symfony Book
    • Screencasts
    • Symfony Bundles
    • Symfony Cloud
    • Training
  • Services
    • SensioLabs Professional services to help you with Symfony
    • Platform.sh for Symfony Best platform to deploy Symfony apps
    • SymfonyInsight Automatic quality checks for your apps
    • Symfony Certification Prove your knowledge and boost your career
    • Blackfire Profile and monitor performance of your apps
  • Other
  • Blog
  • Download
sponsored by SensioLabs
  1. Home
  2. Documentation
  3. Reference
  4. Mailer Configuration Reference (SwiftmailerBundle)
  • Documentation
  • Book
  • Reference
  • Bundles
  • Cloud

Table of Contents

  • Configuration
    • url
    • transport
    • username
    • password
    • command
    • host
    • port
    • timeout
    • source_ip
    • local_domain
    • encryption
    • auth_mode
    • spool
    • sender_address
    • antiflood
    • delivery_addresses
    • delivery_whitelist
    • disable_delivery
    • logging
  • Using Multiple Mailers

Mailer Configuration Reference (SwiftmailerBundle)

Edit this page

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

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

Mailer Configuration Reference (SwiftmailerBundle)

The SwiftmailerBundle integrates the Swift Mailer library in Symfony applications to send emails. All these options are configured under the swiftmailer key in your application configuration.

1
2
3
4
5
# displays the default config values defined by Symfony
$ php bin/console config:dump-reference swiftmailer

# displays the actual config values used by your application
$ php bin/console debug:config swiftmailer

Note

When using XML, you must use the http://symfony.com/schema/dic/swiftmailer namespace and the related XSD schema is available at: https://symfony.com/schema/dic/swiftmailer/swiftmailer-1.0.xsd

Configuration

  • antiflood

    • sleep
    • threshold
  • auth_mode
  • command
  • delivery_addresses
  • delivery_whitelist
  • disable_delivery
  • encryption
  • host
  • local_domain
  • logging
  • password
  • port
  • sender_address
  • source_ip
  • spool

    • path
    • type
  • timeout
  • transport
  • url
  • username

url

type: string

The entire Swift Mailer configuration using a DSN-like URL format.

Example: smtp://user:pass@host:port/?timeout=60&encryption=ssl&auth_mode=login&...

transport

type: string default: smtp

The exact transport method to use to deliver emails. Valid values are:

  • smtp
  • gmail (see How to Use Gmail to Send Emails)
  • mail (deprecated in Swift Mailer since version 5.4.5)
  • sendmail
  • null (same as setting disable_delivery to true)

username

type: string

The username when using smtp as the transport.

password

type: string

The password when using smtp as the transport.

command

type: string default: /usr/sbin/sendmail -bs

Command to be executed by sendmail transport.

host

type: string default: localhost

The host to connect to when using smtp as the transport.

port

type: string default: 25 or 465 (depending on encryption)

The port when using smtp as the transport. This defaults to 465 if encryption is ssl and 25 otherwise.

timeout

type: integer

The timeout in seconds when using smtp as the transport.

source_ip

type: string

The source IP address when using smtp as the transport.

local_domain

2.4.0

The local_domain option was introduced in SwiftMailerBundle 2.4.0.

type: string

The domain name to use in HELO command.

encryption

type: string

The encryption mode to use when using smtp as the transport. Valid values are tls, ssl, or null (indicating no encryption).

auth_mode

type: string

The authentication mode to use when using smtp as the transport. Valid values are plain, login, cram-md5, or null.

spool

For details on email spooling, see How to Spool Emails.

type

type: string default: file

The method used to store spooled messages. Valid values are memory and file. A custom spool should be possible by creating a service called swiftmailer.spool.myspool and setting this value to myspool.

path

type: string default: %kernel.cache_dir%/swiftmailer/spool

When using the file spool, this is the path where the spooled messages will be stored.

sender_address

type: string

If set, all messages will be delivered with this address as the "return path" address, which is where bounced messages should go. This is handled internally by Swift Mailer's Swift_Plugins_ImpersonatePlugin class.

antiflood

threshold

type: integer default: 99

Used with Swift_Plugins_AntiFloodPlugin. This is the number of emails to send before restarting the transport.

sleep

type: integer default: 0

Used with Swift_Plugins_AntiFloodPlugin. This is the number of seconds to sleep for during a transport restart.

delivery_addresses

type: array

Note

In previous versions, this option was called delivery_address.

If set, all email messages will be sent to these addresses instead of being sent to their actual recipients. This is often useful when developing. For example, by setting this in the config_dev.yml file, you can guarantee that all emails sent during development go to one or more some specific accounts.

This uses Swift_Plugins_RedirectingPlugin. Original recipients are available on the X-Swift-To, X-Swift-Cc and X-Swift-Bcc headers.

delivery_whitelist

type: array

Used in combination with delivery_address or delivery_addresses. If set, emails matching any of these patterns will be delivered like normal, as well as being sent to delivery_address or delivery_addresses. For details, see the How to Work with Emails during Development article.

disable_delivery

type: boolean default: false

If true, the transport will automatically be set to null and no emails will actually be delivered.

logging

type: boolean default: %kernel.debug%

If true, Symfony's data collector will be activated for Swift Mailer and the information will be available in the profiler.

Tip

The following options can be set via environment variables using the %env()% syntax: url, transport, username, password, host, port, timeout, source_ip, local_domain, encryption, auth_mode. For details, see the How to Set external Parameters in the Service Container article.

Using Multiple Mailers

You can configure multiple mailers by grouping them under the mailers key (the default mailer is identified by the default_mailer option):

  • YAML
  • XML
  • PHP
1
2
3
4
5
6
7
swiftmailer:
    default_mailer: second_mailer
    mailers:
        first_mailer:
            # ...
        second_mailer:
            # ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?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
        https://symfony.com/schema/dic/services/services-1.0.xsd
        http://symfony.com/schema/dic/swiftmailer
        https://symfony.com/schema/dic/swiftmailer/swiftmailer-1.0.xsd">

    <swiftmailer:config default-mailer="second_mailer">
        <swiftmailer:mailer name="first_mailer"/>
        <swiftmailer:mailer name="second_mailer"/>
    </swiftmailer:config>
</container>
1
2
3
4
5
6
7
8
9
10
11
$container->loadFromExtension('swiftmailer', [
    'default_mailer' => 'second_mailer',
    'mailers' => [
        'first_mailer' => [
            // ...
        ],
        'second_mailer' => [
            // ...
        ],
    ],
]);

Each mailer is registered as a service:

1
2
3
4
5
6
7
8
9
10
// ...

// returns the first mailer
$container->get('swiftmailer.mailer.first_mailer');

// also returns the second mailer since it is the default mailer
$container->get('swiftmailer.mailer');

// returns the second mailer
$container->get('swiftmailer.mailer.second_mailer');

Caution

When configuring multiple mailers, options must be placed under the appropriate mailer key of the configuration instead of directly under the swiftmailer key.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version
    We stand with Ukraine.
    Version:
    Become certified from home

    Become certified from home

    Code consumes server resources. Blackfire tells you how

    Code consumes server resources. Blackfire tells you how

    Symfony footer

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

    Avatar of Stephan Vierkant, a Symfony contributor

    Thanks Stephan Vierkant (@svierkant) for being a Symfony contributor

    3 commits • 32 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