簡體   English   中英

cakePHP-電子郵件客戶端:在本地主機上讀取gmail收件箱

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

我目前正在做一個項目,但仍在本地計算機上工作。 問題是我似乎無法使用此插件連接gmail郵箱

真正的問題是,我不知道使用插件與本地主機上的gmail帳戶連接的代碼。 我在我的配置中有這個:

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',
        ),
    );

然后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

有人知道正確的方法嗎? 或者,如果有可能我可以繼續在本地計算機上進行此操作,如果可以,怎么辦?

[編輯]

在插件代碼中,這就是它為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);
            }

您需要使用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',
        ),
    );

當然可以在您的gmail帳戶上啟用imap ...

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

用於控制器動作

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

對於幫助鏈接
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