我正在将此库https://github.com/secit-pl/imap-bundle与Symfony 4一起使用,以从服务器检索电子邮件,我按照它们放在页面底部的说明进行操作。我正在尝试以Gmail为例。但是我收到此错误消息
在呈现模板的过程中引发了一个异常(未找到“ Service“ secit.imap”服务:即使它存在于应用程序的容器中,“ App \ Controller \ IndexController”内的容器也是一个较小的服务定位符,仅了解“准则”,“ form.factory”,“ http_kernel”,“ parameter_bag”,“ request_stack”,“ router”,“ security.authorization_checker”,“ security.csrf.token_manager”,“ security.token_storage”, “ serializer”,“ session”和“ twig”服务。除非您需要额外的惰性,否则请尝试使用依赖项注入。否则,您需要使用“ IndexController :: getSubscribedServices()”进行声明。)。
我用来连接的代码是
imap.yaml
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"
控制器
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');
}
并进行如下测试
$exampleConnection = $imap->get('example_connection');
$isConnectable = $this->get('secit.imap')->
testConnection('example_connection');
var_dump($isConnectable);
但是显然它找不到服务“ secit.imap”