简体   繁体   English

cakePHP-电子邮件客户端:在本地主机上读取gmail收件箱

[英]cakePHP- Email client: Reading gmail inbox on localhost

I am currently doing a project, but I am still working on the local machine. 我目前正在做一个项目,但仍在本地计算机上工作。 The problem is that I can't seem to connect the gmail mailbox using this plugin 问题是我似乎无法使用此插件连接gmail邮箱

The real problem is, that I do not know the code for connecting with gmail account on localhost using the plugin. 真正的问题是,我不知道使用插件与本地主机上的gmail帐户连接的代码。 I have this in my config : 我在我的配置中有这个:

public $emailTicket = array(
        'datasource' => 'ImapSource',
        'server' => 'localhost',
        'connect' => 'imap/tls/novalidate-cert',
        'username' => '************@gmail.com',
        'password' => '*********',
        'port' => '143', //incoming port 
        'ssl' => false,
        'encoding' => 'UTF-8',
        'error_handler' => 'php',
        'auto_mark_as' => array(
        'Seen',
        // 'Answered',
        // 'Flagged',
        // 'Deleted',
        // 'Draft',
        ),
    );

Then cake returns an error : Error: Unable to get imap_thread after 4 retries. 'Can't connect to **localhostName**,143: Refused 然后cake返回错误: Error: Unable to get imap_thread after 4 retries. 'Can't connect to **localhostName**,143: Refused Error: Unable to get imap_thread after 4 retries. 'Can't connect to **localhostName**,143: Refused

Anyone knows the correct way to do it? 有人知道正确的方法吗? Or if its possible that I continue working on this on the localmachine, if so, how? 或者,如果有可能我可以继续在本地计算机上进行此操作,如果可以,怎么办?

[EDIT] [编辑]

Within the plugin code, this is how it prepares the parameters for php's imap_open() : 在插件代码中,这就是它为php的imap_open()准备参数的方式:

case 'imap':
                $this->_connectionString = sprintf(
                    '{%s:%s%s%s}',
                    $this->config['server'],
                    $this->config['port'],
                    @$this->config['ssl'] ? '/ssl' : '',
                    @$this->config['connect'] ? '/' . @$this->config['connect'] : ''
                );
                break;

$retries = 0;
            while (($retries++) < $this->config['retry'] && !$this->thread) {
                $this->Stream = imap_open($this->_connectionString, $this->config['username'], $this->config['password']);
                $this->thread = @imap_thread($this->Stream);
            }

You need to use the Gmail incoming email imap server settings: 您需要使用Gmail传入电子邮件imap服务器设置:

public $emailTicket = array(
        'datasource' => 'ImapSource',
        'server' => 'imap.gmail.com',
        'connect' => 'imap/tls/novalidate-cert',
        'username' => '************@gmail.com',
        'password' => '*********',
        'port' => '993', //incoming port 
        'ssl' => true,
        'encoding' => 'UTF-8',
        'error_handler' => 'php',
        'auto_mark_as' => array(
        'Seen',
        // 'Answered',
        // 'Flagged',
        // 'Deleted',
        // 'Draft',
        ),
    );

And ofcourse enable imap on your gmail account... 当然可以在您的gmail帐户上启用imap ...

class EmailConfig {
    public $gmail = array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => 465,
        'username' => 'my@gmail.com',
        'password' => 'secret',
        'transport' => 'Smtp'
    );
}

for Controller action 用于控制器动作

App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('gmail');

For Helping Link 对于帮助链接
http://book.cakephp.org/2.0/en/core-utility-libraries/email.html http://www.shahariaazam.com/send-email-from-localhost-in-cakephp-using-cakeemail/# http://book.cakephp.org/2.0/en/core-utility-libraries/email.html http://www.shahariaazam.com/send-email-from-localhost-in-cakephp-using-cakeemail/#

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM