PHPackages                             lucasccs/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. [HTTP &amp; Networking](/categories/http)
4. /
5. lucasccs/imap-bundle

ActiveSymfony-bundle[HTTP &amp; Networking](/categories/http)

lucasccs/imap-bundle
====================

PHP-IMAP Symfony integration.

04PHP

Since Jan 10Pushed 2y ago2 watchersCompare

[ Source](https://github.com/lucascostagoflux/php-imap-bundle-symfony)[ Packagist](https://packagist.org/packages/lucasccs/imap-bundle)[ RSS](/packages/lucasccs-imap-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

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

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

Simple [php-imap](https://github.com/barbushin/php-imap) integration for Symfony 4.4, 5.x and 6.x.

> The version 2.0 and above require PHP 8.0+ and Symfony 4.4+. If you are stuck on previous PHP or Symfony version please use version 1.x.

> The version 1.5 and above are only compatible with Symfony 4+. Previous versions support was dropped. If you'd like to use it with Symfony 2.8 or 3.x you should use the version 1.4 which was the last compatible with Symfony 2.8 and 3.x.

Want to support this bundle?
----------------------------

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

Consider buying our macOS app which allows you to customize your macOS menu bar.

[Infinite Menu Bar](https://infinitemenubar.com/appstore/github-imap-bundle) allows you to add to your menu bar custom elements. Want to have current IP (local or external), Macbook battery state, Bitcoin price or even custom content from any HTTP URL or API? No problem! This app can do this and many more!

[![Infinite Menu Bar](https://camo.githubusercontent.com/d48fdf7c5f8cc6d29e0f6e9d1885e19d21371368a360879412fa23e6ef54567f/68747470733a2f2f696e66696e6974656d656e756261722e636f6d2f6173736574732f69636f6e2d3130302e6a7067)](https://infinitemenubar.com/appstore/github-imap-bundle)

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

[](#installation)

#### 1. Composer

[](#1-composer)

From the command line run

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

```

If you're using Symfony Flex you're done and you can go to the configuration section otherwise you must manually register this bundle.

#### 2. Register bundle

[](#2-register-bundle)

If you're not using Symfony Flex you must manually register this bundle in /config/bundles.php by adding the bundle declaration.

```
return [
  ...
  new SecIT\ImapBundle\ImapBundle(),
];
```

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_connection:
            mailbox: "{localhost:993/imap/ssl/novalidate-cert}INBOX"
            username: "email@example.com"
            password: "password"

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

        full_config_connection:
            mailbox: "{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"
```

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_connection:
            mailbox: "{outlook.office365.com:993/imap/ssl/authuser=first.last@example.com/user=shared_account}Root/Folder"
            username: "email@example.com"
            password: "password"
```

### Security

[](#security)

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_connection:
            mailbox:  '%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 imap-bundle:validate

```

Result:

```
+--------------------------+-------------------+-------------------------------+--------------------+
| Connection               | Connect Result    | Mailbox                       | Username           |
+--------------------------+-------------------+-------------------------------+--------------------+
| example_connection       | SUCCESS           | {imap.strato.de:993/imap/ssl} | user@mail.com      |
| example_WRONG_connection | FAILED: Reason... | {imap.strato.de:993/imap/ssl} | WRONG              |
+--------------------------+-------------------+-------------------------------+--------------------+

```

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 imap-bundle:validate example_connection example_connection2

```

Usage
-----

[](#usage)

#### With autowiring

[](#with-autowiring)

In your controller:

```
