2011-11-17 4 views
0

여기에 언급 된 IMAP 솔루션을 사용해 보았습니다. 내가 CakePHP를 사용하고api를 사용하여 Gmail에서 첨부 파일을 다운로드하는 방법

download gmail attachements from php

. 60 초 후에 시간 초과됩니다.

/* connect to gmail */ 
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX'; 
$username = 'david***@gmail.com'; 
$password = '*********'; 

/* try to connect */ 
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error()); 

/* grab emails */ 
$emails = imap_search($inbox,'ALL'); 

/* if emails are returned, cycle through each... */ 
if($emails) { 

    /* begin output var */ 
    $output = ''; 

    /* put the newest emails on top */ 
    rsort($emails); 

    /* for every email... */ 
    foreach($emails as $email_number) { 

     /* get information specific to this email */ 
     $overview = imap_fetch_overview($inbox,$email_number,0); 
     $message = imap_fetchbody($inbox,$email_number,2); 

     /* output the email header information */ 
     $output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">'; 
     $output.= '<span class="subject">'.$overview[0]->subject.'</span> '; 
     $output.= '<span class="from">'.$overview[0]->from.'</span>'; 
     $output.= '<span class="date">on '.$overview[0]->date.'</span>'; 
     $output.= '</div>'; 

     /* output the email body */ 
     $output.= '<div class="body">'.$message.'</div>'; 
    } 

    echo $output; 
} 

/* close the connection */ 
imap_close($inbox); 

감사합니다.

감사합니다.

+0

: https://github.com/dereuromark/tools/blob/2.0/Lib/ImapLib.php

은 기본적으로 내 모델 내에서 다음과 같이 사용하십시오. – nickb

답변

1

Apache Zeta Components의 Mail 구성 요소로 연결하겠습니다. (단지 튜토리얼을 따라)

예제 코드를 난 그냥 다른 하루와 놀겠다는 거 WAAS 및 Gmail에 모두 전송하고 검색하는 첨부 파일은 정말 쉬웠다 :

<?php 

error_reporting(E_ALL); 

require_once('classes/zeta/Base/src/ezc_bootstrap.php'); 

spl_autoload_register(array('ezcBase', 'autoload')); 

$options = new ezcMailImapTransportOptions(); 
$options->ssl = true; 

$imap = new ezcMailImapTransport("imap.gmail.com",993,$options); 

$imap->authenticate("[email protected]","password"); 
$mailboxes = $imap->listMailboxes(); 

$imap->selectMailbox('[Gmail]/All Mail'); 

$set = $imap->fetchAll(); 

$parser = new ezcMailParser(); 

$mail = $parser->parseMail($set); 

for ($i = 0; $i < count($mail); $i++) 
{ 

    // Process $mail[$i] such as use $mail[$i]->subject, $mail[$i]->body 
    echo "From: {$mail[$i]->from}, Subject: {$mail[$i]->subject}\n"; 
    // Save the attachments to another folder 
    $parts = $mail[$i]->fetchParts(); 
    foreach ($parts as $part) 
    { 
     if ($part instanceof ezcMailFile) 
     { 
      rename($part->fileName, __DIR__ . '/' . basename($part->contentDisposition->displayFileName)); 
     } 
    } 
} 
1

당신은 내은 imaplib을 시도 할 수 있습니다. 는 PDF 첨부 파일 나를 위해 일한 : 당신은 당신의 문제에 대한 자세한 내용은 해봤 코드를 게시하거나 제공해야합니다

$code = 'privat'; 
    $account = Configure::read('Mailbox.'.$code); 
    if (!$account) { 
     trigger_error('Credentials missing for '.$code); 
     return array(); 
    } 

    App::import('Lib', 'Tools.ImapLib'); 
    $Imap = new ImapLib(); 
    $Imap->set('service', 'pop3'); 
    $res = $Imap->connect($account['address'], $account['password'], Configure::read('Mailbox.host')); 
    if (!$res) { 
     return array(); 
    } 
    $messages = $Imap->msgList(); 
    return $messages; 
관련 문제