Trigger PHP Script on New Email (Google Apps / Gmail) - php

Is there any way to trigger a php script when a new email arrives on Google Apps (Gmail)? I've figured out a way to poll the inbox to look for new messages, but I'd ideally like a more event-based solution. Basically I need it to be run from a server somewhere which would parse new email messages and process itself according to the contents of the message.

Most mail transfer agents let you put in filters that can process incoming mail through a program as it arrives. SpamAssassin works this way, for example.
Because Gmail is hosted, you can't exactly do that.
The only realistic answer in this case is polling. Thankfully Gmail exposes both POP3 and IMAP access, so checking should be very simple. There are a few comprehensive mail reading libraries out there, or you could be insane and poke at IMAP directly.
Edit: Because you're on Google Apps, there's also an Atom feed of unread messages, though you'd still need something to poll the feed, unless you happen to have something handy that will do the polling for you and fire up requests. I vaguely recall something like this existing, but I don't recall what it's called...

It's possible now, using Google Apps Scripts. You have to create a script and attach a trigger to it to run every 1 minute or so. If a new email is found, just invoke your URL.

Related

How to sync Laravel Application with Email Server

I am trying to Create a Mail Box for each user and each user account will be connected to his email(Gmail, Outlook, etc). Now I am trying to connect email in real-time whenever they receive an email they also get in their mailbox. I can get receive the email through IMAP but it is not real-time I have to look for a new email after a specific time. I am looking for a package or library that can do it easily for me or any other solution. After searching I get only one solution which is IMAP and I also implemented it but now I need another solution that fits exactly. If anyone has any idea pls share. and what if I set up my own custom email server with a custom domain so how can I create such functionality with Laravel.
Why I am doing all this?
beceause I want this real time when ever user receive email his ticket will be created on behalf of email it does not need to wait until IMAP fetch and then ticket will be created or displayed.
Thanks in advance.
You do not really have any other option besides IMAP, unless you want to pair with specific services like Exchange Web Services.
PHP has a very comprehensive set of functions regarding IMAP. I would suggest checking it out. Unfortunately, there is not really anything you can do from within PHP to prevent having to poll.
My suggestion is checking in the background if new mails have arrived. For example by checking from within a cronjob. That way you don't have to initiate a new connection to an IMAP server every time a users visits the page.
IMAP docs

Push messages to android using PHP without GCM or FCM

I need some methods for pushing JSON messages to android application from the server using PHP but without GCM or FCM.
I don't want to use Google because it sometimes doesn't send messages or they arrive in late, and I need a reliable service.
My goal is to update some text views when something happens on the server, for example, a user subscribes for a live game, so other users see the number of players increased real-time.
Also, I'm a little ashamed, I'm not able to use other server languages except PHP, and even if I could, my hosting service is not able to install Node or other languages. Moreover, my hosting server doesn't support the composer, so I need to install libraries manually.
I try to use Pusher, and it works fine, but it costs too much if one day I reach a good number of players. Actually, my budget is 0 :(
I also heard about Socket.io but I don't know how to use it with PHP. If someone uses it with PHP I'm really happy to see a front-end and back-end simple examples.
Does anyone have a solution?
Your use case would be best served with something like Firebase Realtime Database or Cloud Firestore or if you want your own server stack, something like Parse.
Doing this will avoid the use of server side code. Also you can react to real time changes with all of the above. All these intrinsically do run over Sockets so instead of rolling out your own, i suggest you have a look at these and try to fit these for your use case.
Using notifications for this is kind of an overkill and may cause your app to get blacklisted for overly spamming users.

Send a mail on every chat message

I am currently using pubnub chat in one of the my application. And now I want to add functionalities like on each and every chat message I want to send mail,same as upwork website is doing.
For the same I have contacted pubnub support but they are not providing any such feature, So I need to send mails from my end, mostly by calling ajax and send mail from php.
But the major issue here is as its chat feature may I need to send number of mails (mass mail) in very short time. So my server doesn't supports it.
So how to implement mass mailing.
Check Out PubNub BLOCKS
PubNub BLOCKS is a set of customizable microservices that give
developers a simple way to add code and deploy features for realtime
apps. PubNub BLOCKS execute business logic directly on the data
streaming through PubNub’s network without splitting it off to an
intermediary server controlled by the customer. This revolutionary
approach streamlines app development, reduces endpoint-to-endpoint
latency, and allows apps to better leverage the enormous scalability
of PubNub’s Data Stream Network.
Sending email (or a Tweet, SMS, etc) with every published message, or only messages with an attribute such as email=true, is something that will be implemented as a BLOCK that you will be able to use out-of-the-box. Custom BLOCKS can be implemented to do whatever else you need to do for every message or certain messages without your server(s) getting invovled.
With cakePHP I would suggest saving the E-Mails to be sent in a queue with a short Ajax call. This can be done with a json view. Then you can create a cron that calls the CakePHP Shell to send the mails with the standard CakePHP Mailer.
If the Mails are time-critical or you don't have access to the server (cron) you can also send the mails directly on the ajax call. The advantage of the cron is that the call (from the browser) is short and that the mails (depending on the server) might need more time to be sent.
Here is an answer that might help you implementing it.

Webmail client with google imap

Im developing a webmail client using Zend framework and gmail IMAP.
Features like moving email from one folder to another ,Flagging,
mail composing,Drafts etc.
Simply it should reflect the same way as you see in the Gmail.
Technically Can any body point me towards right direction.? I mean the zend library supports REST ,JSON,IMAP,
As far as database is concerned im fine and im able to get all the data around 100 MB of data im able to store.
How should my approach be as far as architecture is concerned.Does REST & GMAIL IMAP combinedly can be used to perform manipulations ?
because always the server should always get new mail instantly may be at 5-10 min gap .
PLEASE Advise.
Also does gmail provide REST support to get new emails? OR we have to develop REST SERVER and consume the Rest client?
Also i would appreciate good hyper links to point over for kind of architecture.
Thanks
Mark
Technically Can any body point me towards right direction.? I mean the zend library supports REST ,JSON,IMAP,
These three acronyms have nothing do to with each other.
REST is an architectural philosophy.
JSON is a data encoding format.
IMAP is a protocol for accessing mailboxes.
Yes, Zend Framework has components that deal with all of these things, but that doesn't mean you have to use all of them.
If you want to access your Gmail account through IMAP, then use one of the Zend_Mail_Storage classes.
Does REST & GMAIL IMAP combinedly can be used to perform manipulations ?
If by that you mean "Can I write a RESTful application that uses IMAP to communicate to Gmail?", then the answer is yes, yes you can.
the server should always get new mail instantly may be at 5-10 min gap
It sounds like you want a cron job running to continuously poll the server for mail, instead of using an active IMAP connection live whenever the user is making requests.
Also does gmail provide REST support to get new emails?
It took them years to give us just basic IMAP support, I don't think we're going to see a RESTful API out of them any time soon. Keep in mind that they earn money based off of ad views. You aren't viewing ads when you use IMAP.
Also i would appreciate good hyper links to point over for kind of architecture.
Are you kidding? No, really, look at what you're doing. You're building a webmail client designed to access another webmail client. Do you realize how incredibly silly that is, my friend? You're re-inventing a re-invented wheel.
I don't know of a single worthwhile webmail client outside of Gmail. If you want to study the architecture of other webmail clients in PHP, then take a look at IMP (designed for PHP 4, and therefore ancient), Roundcube, or SquirrelMail. I am not responsible for any brain damage you suffer from reading the source.

PHP: Can we build a web application to send email from localhost, like ThunderBirds, OutLook.?

I don't know whether or not it's a good question :(
But my intention is to know if it is possible to to build an email client application like Thunderbird or OutLook . And can we able to configure/create a Web Application in PHP?
Please let me know your thoughts!
Thanks in advance!!!
I am not sure that I understand the question, but here a couple of notes :
if you want to create a web application, of course you can use PHP : it's been created for that task, and does it well
if you want to develop a webmail (ie, a web application to send/receive mail), it'll mean lots of work...
maybe taking a look at some existing webmails might be wiser ?
About that, you might be interested by my answer to the question How do you build a web based email client using PHP?
if you want to create a desktop application, this is possible too ;-)
take a look at PHP-GTK (GTK is the graphic toolkit used for Gnome and/or the Gimp, for instance), about that ; here are a couple links :
Desktop Application Development with PHP-GTK
Beginning PHP-GTK: Creating a Simple Interface
Beginning PHP-GTK: Signals
Uh, sure, but why would you do so? Thunderbird is free and open-source. You could just use that. Unless you've a compelling reason to develop an entirely new e-mail client, it's better not to reinvent the wheel.
Plenty of open-source webmail clients already exist, too. RoundCube is one of the prettiest.
PHP is usually used as a server-side scripting language to build web applications. It does have the functionality that you need to be able to send email messages from a properly configured server.
The mail should definitely be sent from the server not the local machine, but its perfectly ok to create a webmail system. Also you can retrieve incoming mails from your mail server. Actually there are webmail clients on the market that you can use. I personally like Squirrel Mail
I would recommend in your case that you look at using PHP as core backend and (x)html+javascript+ajax for frontend and front-to-backend communications.
Ajax is very good for dynamic pages where you do not want page reloads etc.
You could have a local smtp server to send the email, but most internet providers would not allow this. If the later is the case you need to use the internet providers smtp, alternatively allow the configuration of smtp within the user interface.
PHP has builtin classes to send mail which makes this process easy in either case.
Receiving mail and parsing them correctly is just a matter of understanding the correct protocols. (pop3 / exchange and so on).
I know this wasn't a straightforward answer, but I hope it gave at least some insight.

Categories