PHPackages                             secit-pl/imap-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. secit-pl/imap-bundle

ActiveSymfony-bundle[Mail &amp; Notifications](/categories/mail)

secit-pl/imap-bundle
====================

PHP-IMAP Symfony integration.

3.2.1(1y ago)711.5M↓14.4%20[2 issues](https://github.com/secit-pl/imap-bundle/issues)2MITPHPPHP &gt;=8.1

Since Jul 4Pushed 1y ago3 watchersCompare

[ Source](https://github.com/secit-pl/imap-bundle)[ Packagist](https://packagist.org/packages/secit-pl/imap-bundle)[ Docs](https://secit.pl)[ RSS](/packages/secit-pl-imap-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (19)Used By (2)

PHP-IMAP integration bundle
===========================

[](#php-imap-integration-bundle)

Simple [php-imap](https://github.com/barbushin/php-imap) integration for Symfony.

Compatibility matrix
--------------------

[](#compatibility-matrix)

Bundle versionMaintainedSymfony versionsMin. PHP version3.xYes6.4 to 7.x8.1.02.1No4.4 to 6.48.0.01.5No4.0 to 4.35.4.01.4No2.8 to 3.45.4.0Want to support this bundle?
----------------------------

[](#want-to-support-this-bundle)

Consider using our [random code generator](https://codito.io/) service at [codito.io](https://codito.io/).

With [codito.io](https://codito.io/) you can generate up to 250,000 codes in the format of your choice for free. You can use the generated codes for purposes such as promotional codes (which you can, for example, print on the inside of packaging), serial numbers, one-time or multi-use passwords, lottery coupons, discount codes, vouchers, random strings and much more - for more use cases see our [examples](https://codito.io/free-random-code-generator/examples). If 250,000 codes are not enough for you, you can use our [commercial code generation service](https://codito.io/commercial-code-generator/).

[![Random Code Generator](https://camo.githubusercontent.com/06fcfbee43d9df2084536628f12e31577a98295a02e20b428172133530864f8b/68747470733a2f2f636f6469746f2e696f2f6275696c642f66617669636f6e732f6c6f676f2e65353666376662312e77656270)](https://codito.io/)

Installation
------------

[](#installation)

#### 1. Composer

[](#1-composer)

From the command line run

```
composer require secit-pl/imap-bundle
```

Configuration
-------------

[](#configuration)

To set up your mailbox configuration open the `config/packages/imap.yaml` and adjust its content.

Here is the example configuration:

```
imap:
    connections:
        example:
            imap_path: "{localhost:993/imap/ssl/novalidate-cert}INBOX"
            username: "email@example.com"
            password: "password"

        another:
            imap_path: "{localhost:143}INBOX"
            username: "username"
            password: "password"
            attachments_dir: "%kernel.project_dir%/var/imap/attachments"
            server_encoding: "UTF-8"

        full_config:
            imap_path: "{localhost:143}INBOX"
            username: "username"
            password: "password"
            attachments_dir: "%kernel.project_dir%/var/imap/attachments"
            create_attachments_dir_if_not_exists: true # default true
            created_attachments_dir_permissions: 777 # default 770
            server_encoding: "UTF-8"
            enabled: true
```

If you're using Symfony to connect to a Microsoft 365 business environment, there's a good chance you'll want to connect to a shared mailbox. In that case you need to specify the parameters `authuser` and `user`. Where *shared\_account* is the username without domain, like:

```
imap:
    connections:
        example:
            imap_path: "{outlook.office365.com:993/imap/ssl/authuser=first.last@example.com/user=shared_account}Root/Folder"
            username: "email@example.com"
            password: "password"
```

### Security

[](#security)

It's good practice to do not set the sensitive data like mailbox, username and password directly in the config-files. You may have to [encode the values](https://symfony.com/doc/current/doctrine.html#configuring-the-database). [Configuration Based on Environment Variables](https://symfony.com/doc/current/configuration.html#configuration-based-on-environment-variables)[Referencing Secrets in Configuration Files](https://symfony.com/doc/current/configuration/secrets.html#referencing-secrets-in-configuration-files)Better set them in `.env.local`, use Symfony Secrets or CI-Secrets.

```
imap:
    connections:
        example:
            imap_path:  '%env(EXAMPLE_CONNECTION_MAILBOX)%'
            username: '%env(EXAMPLE_CONNECTION_USERNAME)%'
            password: '%env(EXAMPLE_CONNECTION_PASSWORD)%'
```

### Dump actual config:

[](#dump-actual-config)

```
php bin/console debug:config imap
```

### Validate if the mailboxes can connect correct

[](#validate-if-the-mailboxes-can-connect-correct)

```
php bin/console secit:imap:validate-connections
```

Result:

```
+------------------+---------------------+---------------------------------+--------------------+---------+
| Connection       | Connect Result      | Mailbox                         | Username           | Enabled |
+------------------+---------------------+---------------------------------+--------------------+---------+
| example          | SUCCESS             | {imap.example.com:993/imap/ssl} | user@mail.com      | YES     |
| example_WRONG    | FAILED: Reason..... | {imap.example.com:993/imap/ssl} | WRONG              | YES     |
| example_DISABLED | DISABLED            | {imap.example.com:993/imap/ssl} | user2@mail.com     | NO      |
+------------------+---------------------+---------------------------------+--------------------+---------+

```

This command can take some while if any connection failed. That is because of a long connection-timeout. If you use this in CI-Pipeline add the parameter `-q`. Password is not displayed for security reasons. You can set an array of connections to validate.

```
php bin/console secit:imap:validate-connections example example2

```

Usage
-----

[](#usage)

Let's say your config looks like this

```
imap:
    connections:
        example:
            imap_path: ...

        second:
            imap_path: ...

        connection3:
            imap_path: ...
```

You can get the connection inside a class by using service [autowiring](https://symfony.com/doc/current/service_container/autowiring.html) and using camelCased connection name + `Connection` as parameter name.

```
