0

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

The real problem is, that I do not know the code for connecting with gmail account on localhost using the plugin. 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

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() :

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);
            }
LogixMaster
  • 586
  • 2
  • 11
  • 36
  • Something like [this link](http://stackoverflow.com/questions/712392/send-email-using-gmail-smtp-server-from-php-page)? – loveNoHate Feb 07 '14 at 09:59
  • @dollarvar Hi sir, No, I am trying to read the emails using php's imap(or rather the plugin make's use of php's [imap_open](http://www.php.net/imap_open)) . The idea is to create a mini email client within the application – LogixMaster Feb 07 '14 at 10:03
  • Ok, I tried to google that, but I guess you need an `IP` or some address from Googlemail instead of localhost? – loveNoHate Feb 07 '14 at 10:07
  • @dollarvar, wel I tried what the plugin suggested, such as `server=> imap.gmail.com`, but no luck! I'm not very savvy when it comes to these things – LogixMaster Feb 07 '14 at 10:17

2 Answers2

1

You need to use the Gmail incoming email imap server settings:

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...

  • Thank you for answering!! I have tried this and this returns : `Error: Unable to get imap_thread after 4 retries. '[CLOSED] IMAP connection broken (server response)'` Any ideas why this happens? – LogixMaster Feb 07 '14 at 10:27
  • 1
    @user2678538 have you enabled imap on your gmail account? Try debugging the plugin and take a look at: http://www.php.net/manual/en/function.imap-open.php – Bart Van Remortele Feb 07 '14 at 10:34
  • Yes, I do have imap enabled on google.. I've also already looked at php's imap_open. I messed around with the plugin to see how it prepared the connect string for the imap_open method! I edited my question to show this. ALso I found this http://forums.phpfreaks.com/topic/99250-solved-imap-open-imap-connection-broken-problem/, but Im not sure if its my problem, might have to try it out! – LogixMaster Feb 07 '14 at 10:45
  • Perhaps this would be useful aswell: http://www.php.net/manual/en/function.imap-thread.php#104056 – Bart Van Remortele Feb 07 '14 at 11:04
-1
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/#

Zohaib Yunis
  • 376
  • 5
  • 11