Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMAP Driver #59

Open
bobmulder opened this issue Mar 27, 2020 · 9 comments
Open

IMAP Driver #59

bobmulder opened this issue Mar 27, 2020 · 9 comments

Comments

@bobmulder
Copy link

bobmulder commented Mar 27, 2020

Hi there!

This package looks really cool and promising :)

I'd like to use this tool for my clients in my SAAS. However, most of them will not be able to manage their DNS settings to set up a service like Sengrid. For them it would be easier (and more secure in my opinion) to enter an IMAP configuration.

Can you give me any direction? This is not possible at the moment right? And, I probably would need to create a custom driver, right?

Since you'd need to do an active request towards IMAP (instead of having a webhook), this would need another approach I am afraid, which is totally out of scope of this library...

EDIT: The best solution that came up in my mind: we could use the webhook (like all drivers do) to do a 'pull' from the IMAP mailbox. The webhook should be triggered using a cron (like cron-job.org). This way we keep it the way most drivers work.

Regards, Bob

@Remo
Copy link

Remo commented May 19, 2020

I got the same question, but I'm hesitant about using a webhook to initiate an IMAP connection.

I feel like it would be cleaner to have a ConsoleDriverInterface. A dedicated interface would be nice as we could then implement several console interfaces. Some ideas:

I would be keen to use the second option as it would be a low overhead approach. It would also be very fast as our console script would be triggered immediately. Not something everybody would be willing to set up, but still pretty cool.

@bobmulder
Copy link
Author

@Remo I left this idea for a while but I'm thinking about the best approach for an IMAP integration. Did you get further on this?

Your idea about the ConsoleDriverInterface sounds better than my idea bout the webhook ;P

@Remo
Copy link

Remo commented Sep 16, 2020

No, I'm afraid, I didn't do anything here. I was hoping for a feedback from one of the maintainers as I don't want to create a pull request for which there's no interest. We've implemented a work around for the time being, but I'd still be interested in using a higher quality and better maintained solution. Switch to laravel-mailbox is very low priority at this point though.

@vesper8
Copy link

vesper8 commented Dec 11, 2020

What are you using right now @Remo ? I'm confused as to whether it's currently possible to use this package with IMAP/POP and periodically check for new mail.

@Remo
Copy link

Remo commented Dec 11, 2020

I'm not using this package for now. We've built a custom solution based on this https://github.com/mlocati/IMAP

@vesper8
Copy link

vesper8 commented Dec 11, 2020

Thank you for your reply and for sharing your solution

I've just now started looking into https://github.com/Webklex/laravel-imap

I'm curious, considering it has a lot more stars and active development, is there any reason why you opted not to use https://github.com/Webklex/laravel-imap and chose to use https://github.com/mlocati/IMAP instead?

@Remo
Copy link

Remo commented Dec 11, 2020

I know the guy who wrote it, that's pretty much my main reason 😬

@vesper8
Copy link

vesper8 commented Dec 11, 2020

I feel like it wouldn't be very hard at all to have either of those packages hitting a laravel-mailbox endpoint. Either with a custom driver or just mimicking one of the existing ones

@vesper8
Copy link

vesper8 commented Dec 11, 2020

So I decided to take a crack at combining laravel-mailbox with laravel-imap and the whole thing was rather simple to put together. Here's a very short example.

First install https://github.com/beyondcode/laravel-mailbox and https://github.com/Webklex/laravel-imap and publish migrations/config

You can then define your laravel-mailbox mailboxes (to/from/catchall/etc) inside your AppServiceProvider as usual. You don't have to configure any driver, just leave it to the default Log driver. Then you can do something like this

$client =\Webklex\IMAP\Facades\Client::account('default');
$client->connect();

$folder = $client->getFolder('INBOX');

$recentMessages = $folder
->query()
->since(\Carbon\Carbon::now()->subWeeks(1))
->get();

$this->info(sprintf('There are %d messages from the last 1 weeks in %s', $recentMessages->count(), 'INBOX'));

foreach ($recentMessages as $message) {
    $inboundEmail = \BeyondCode\Mailbox\InboundEmail::fromMessage($message->getHeader()->raw . $message->getRawBody());
    if (!\BeyondCode\Mailbox\InboundEmail::where('message_id', $inboundEmail->message()->getHeaderValue('Message-Id'))->exists()) {
        $inboundEmail->save();
        \BeyondCode\Mailbox\Facades\Mailbox::callMailboxes($inboundEmail);
    }
}

And that's it, your inbound_emails table will be filled and your mailboxes will be invoked where you can do additional processing such as auto-replying or triggering events etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants