2017 © Pedro Peláez
 

yii2-extension yii2-imap

yii2 extension to read and process mails from IMAP and PHP

image

unyii2/yii2-imap

yii2 extension to read and process mails from IMAP and PHP

  • Friday, January 26, 2018
  • by uldisn
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1,904 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 15 Forks
  • 0 Open issues
  • 3 Versions
  • 12 % Grown

The README.md

yii2 Imap

Total Downloads, (*1)

This library is a fork of https://github.com/yiioverflow/yii2-imap, (*2)

Installation by composer

{
    "require": {
       "unyii2/yii2-imap": "dev-master"
    }
}

Or

$ composer require unyii2/yii2-imap "dev-master"

Use as compnent

Connection details define in component, (*3)

'components' => [
      ...
      'imap' => [
         'class' => 'unyii2\imap\Imap',
         'connection' => [
              'imapPath' => '{imap.gmail.com:993/imap/ssl}INBOX',
              'imapLogin' => 'username',
              'imapPassword' => 'password',
              'serverEncoding'=>'encoding', // utf-8 default.
              'attachmentsDir'=>'/'
        ],
    ],
    ...
 ],


//4th Param _DIR_ is the location to save attached files 
//Eg: /path/to/application/mail/uploads.
$mailbox = new unyii2\Mailbox(yii::$app->imap->connection);

Usage as library

Connection details set on fly, (*4)


$imapConnection = new unyii2\imap\ImapConnection $imapConnection->imapPath = '{imap.gmail.com:993/imap/ssl}INBOX'; $imapConnection->imapLogin = 'username'; $imapConnection->imapPassword = 'password'; $imapConnection->serverEncoding = 'encoding'; // utf-8 default. $imapConnection->attachmentsDir = '/'; //4th Param _DIR_ is the location to save attached files //Eg: /path/to/application/mail/uploads. $mailbox = new unyii2\Mailbox($imapConnection);

To get all mails and its index

$mailbox->searchMailBox(ALL)// Prints all Mail ids.
print_r($mailIds);

Do not read attachments

$mailbox->readMailParts = false;, (*5)

To read Inbox contents

foreach($mailIds as $mailId)
{
    // Returns Mail contents
    $mail = $mailbox->getMail($mailId); 

    if(alreadyProcesedMessage($mail->messageId)){
        continue;
    }

    // Use, if $mailbox->readMailParts = false; 
    // Read mail parts (plain body, html body and attachments
    $mail = $mailbox->getMailParts($mail);

    // Returns mail attachements if any or else empty array
    $attachments = $mail->getAttachments(); 
    foreach($attachments as $attachment){
        echo ' Attachment:' . $attachment->name . PHP_EOL;

        // Delete attachment file
        unlink($attachment->filePath);

    }
}

To Mark and delete mail from IMAP server.

//Mark a mail to delete</span></span> 
$mailbox->deleteMail($mailId); // Deletes all marked mails
$mailbox->expungeDeletedMails();

Contribute

Feel free to contribute. If you have ideas for examples, add them to the repo and send in a pull request., (*6)

Apreciate

Dont forgett o Leave me a "star" if you like it. Enjoy coding!, (*7)

The Versions

26/01 2018

dev-master

9999999-dev https://github.com/yiioverflow/yii2-imap.git

yii2 extension to read and process mails from IMAP and PHP

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.4.0

 

mail extension yii2 widget imap cron inbox

26/01 2018

0.5.1

0.5.1.0 https://github.com/yiioverflow/yii2-imap.git

yii2 extension to read and process mails from IMAP and PHP

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.4.0

 

mail extension yii2 widget imap cron inbox

30/12 2017

0.5.0

0.5.0.0 https://github.com/yiioverflow/yii2-imap.git

yii2 extension to read and process mails from IMAP and PHP

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.4.0

 

mail extension yii2 widget imap cron inbox