PHP-IMAP integration bundle
Simple php-imap integration for Symfony 2.8, 3.x, 4.x and 5.x.
Want to support this bundle?
Consider buying our MacOS app which allows you to customize your MacOS menu bar.
Infinite Menu Bar 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 contet from any HTTP URL or API? No problem! This app can do this and many more!
Installation
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
If you're not using Symfony Flex you must manually register this bundle in your AppKernel by adding the bundle declaration
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
...
new SecIT\ImapBundle\ImapBundle(),
];
...
}
}
Configuration
Setup your mailbox configuration. If your are using symfony 2.8 or 3.x without Symfony Flex add your configuration in app/config/config.yml
.
If you're using Symfony 4 or Symfony 3.x with Flex 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.root_dir%/../var/imap/attachments"
server_encoding: "UTF-8"
Usage
With autowiring
In your controller:
<?php
namespace App\Controller;
use SecIT\ImapBundle\Service\Imap;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class IndexController extends AbstractController
{
public function indexAction(Imap $imap)
{
$exampleConnection = $imap->get('example_connection');
$anotherConnection = $imap->get('another_connection');
...
}
...
}
With service container
In your controller:
<?php
namespace App\Controller;
use SecIT\ImapBundle\Service\Imap;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class IndexController extends Controller
{
public function indexAction()
{
$exampleConnection = $this->get('secit.imap')->get('example_connection');
$anotherConnection = $this->get('secit.imap')->get('another_connection');
...
}
...
}
From this point you can use any of the methods provided by the php-imap library. For example
$exampleConnection = $this->get('secit.imap')->get('example_connection');
$exampleConnection->getMailboxInfo();
To quickly test the connection to the server you can use the testConnection()
method
// testing with a boolean response
$isConnectable = $this->get('secit.imap')->testConnection('example_connection');
var_dump($isConnectable);
// testing with a full error message
try {
$isConnectable = $this->get('secit.imap')->testConnection('example_connection', true);
} catch (\Exception $exception) {
echo $exception->getMessage();
}
Be aware that this will disconnect your current connection and create a new one on success. In most cases this is not a problem.
Copyright (c) 2017 secit.pl
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
imap:
connections: # Required
mailbox: ~ # Required
username: ~ # Required
password: ~ # Required
attachments_dir: ~
server_encoding: ~
-
Updated readme
By secit-pl, 1 year ago
-
Allow installation on Symfony 5
By web-flow, 1 year ago
-
Fixed Symfony 4.2 deprecations
By web-flow, 2 years ago
-
Added support information to readme
By web-flow, 2 years ago
-
Fixed usage example in documentation
By secit-pl, 2 years ago
-
Autowiring support
By secit-pl, 2 years ago
-
Added attachments directory existence checking
By secit-pl, 3 years ago
-
Merge branch 'master' of https://github.com/secit-pl/imap-bundle
By secit-pl, 3 years ago
-
php-imap/php-imap ~3.0 support
By secit-pl, 3 years ago
-
Merge pull request #1 from phansys/branch-alias
By web-flow, 3 years ago
-
Add `extra.branch-alias` config at `composer.json` in order to allow installs from dev versions while respecting SemVer
By phansys, 3 years ago
-
Documentation update for Symfony 4/Flex support
By secit-pl, 3 years ago
-
Service secit.imap should public in all cases
By web-flow, 3 years ago
-
Allow empty connections list
By web-flow, 3 years ago
-
Update composer.json
By web-flow, 3 years ago
-
Added missing semicolon in the connection test example source code
By web-flow, 3 years ago
-
Merge branch 'master' of https://github.com/secit-pl/imap-bundle
By secit-pl, 3 years ago
-
Added possibility to quickly test the server connection
By secit-pl, 3 years ago
-
Added license file
By web-flow, 3 years ago
-
Fixed main title in README.md
By secit-pl, 3 years ago
-
Initial implementation
By secit-pl, 3 years ago
-
Initial commit
By secit-pl, 3 years ago