How to receive email GMAIL with LARAVEL? - php

I want to receive my mail (INBOX GMAIL) in my laravel application (5.x).
But I don't know how to do this.
I think I need to use a listener : when a mail arrives in my INBOX, I want a laravel event to read the email and save automatically the fields in my database (Subject, Message, Attachments...).
Then the mail in my INBOX will be in status "read".
Can you help me ?
Thank you :)

Interesting way to look at this but why not just have it send messages to the ticketing system and completely manage it there?
You would need to take a look at https://developers.google.com/gmail/api/v1/reference/
Basically you would just be managing emails in a different application. There are also rate limits to be aware of depending on the scope of this system.
It would be safer in that event to have gmail forward the emails to the ticketing system and 100% manage it there and use SMTP to just reply from the system.

Related

How does GitHub 'Reply by Email' work?

I notice that a lot of websites like Facebook and GitHub allow you to reply to an email notification which then posts the reply back to the application using a unique Reply-To address. How does this work on the back-end? I searched a lot but, only found that people were using unique Reply-To addresses. That's understandable but, what do they use to receive these emails? Do these companies set up email servers? I am trying to build this using PHP.
A common method is to set unique message ID's in the outgoing email and then looking at the In-Reply-To header to see which email this was in reply to. That lets you match up your server application's messaging system to emails. For example, if you send an email that represents a help desk ticket with ID 1234, the Message-ID could be something like
ticket-1234#myserver
Then, in email clients that work nicely (I'm looking at you Android), when you hit Reply, the reply has the header In-Reply-To: ticket-1234#mysever. You can go further by adding security tokens to ensure people can't forge messages (e.g. ticket-1234-hf29e9f2gf2e9fh29f#myserver). That security token is generated on the server when you send your first message and is then confirmed in the reply.
This normally works but can cause real headaches when email clients don't behave as they should!
This is how GitLab manages emails by using an identifier in the email address itself and catching it when the user replies. Although it is not relevant to any scripting language like PHP and uses server configs, this is what backend servers do to support reply by email functionality.
You have to set up a mail server to receive mail answers.
SIEVE filters on a IMAP server could be use to make some actions when a certain filter is detected.
But you can't only use PHP to make that type of system.

Send mail with external data through PHP

I looking into building a system that can read and send mails all by itself.
The mailserver already exists. All I want to do is fetch the e mail data with a php script running locally on the mailserver, store some of the data in an external database.
Then when an "event" is raised, I want to run a php script that get's some data out of the database, create a mail , and send it through the mail server.
I'm fairly new to this, so I hope the things I say make sense.
Here's my question: Is it secure enough to work this way?
Am I doing anything against "the rules" ?
Thanks
There is nothing wrong in doing the things this way. Its not against the rule. But Email Deliverability is not guaranteed because:
There is no guarantee that the email you send will pass the spam filters of email providers.
Number of emails you send to 1 user in a day, Any spam keyword in the mail content, user marking your email as spam etc.
Basically, there are n number of reasons why your mail server might get blacklisted by email providers.
To ensure Email Deliverability, you need to get your mail server IP whitelisted with all the email providers. (which is not easy)
I would suggest you to use bulk email sending third party solutions like Sendgrid, Madmimi, etc.
Refer: Discussion on choosing email sending service
Also, these services also gives statistics like open tracking, click tracking etc...

how to receive and validate incoming mail for web based mails in php

We are developing a email web site.but we are facing problem in receiving and validating the mail.i have the following doubts.can you please help me in clarifying these???
one more important thing is we are not using squrrelmail, qmail etc.
how do we receive emails for users in email web site?
do we save all the received emails in admin's mail box or in database as per the username
(my idea on email web site is,all the incoming mail are stored in admin's mail box and after the email mail is stored in database,and then the mail deleted in admin's mail box.Is it correct.if not how to store the emails in database directly in web site)
what is the technique behind the receiving mail???i think there are various techniques like email piping etc.
is there any special process of creating users for email web site,i mean do we need to create mailbox(i think mail account) for each user at the time of registration.if we need to create mail box for user,can we create it with imap_createmailbox() function.
are the users gmail,yahoomail etc are accessig database or their mail accounts at the time their login??
can we do all these things with imap functions in php??
There are many different solutions to this problem, polling existing servers, adding scripts to run when a message is received or using a gateway like CloudMailin. I wrote a blog post relating to this (it's for rails but almost all applies to php too).
The other problems almost all span from how you setup the first thing. In many cases you could just log the emails directly to your database and retrive them based on the recipient address. I think you need to explain exactly what you want to do with the email? Are you just providing email hosting for your users or are you providing an additional service? If you're just providing hosting then there are simpler approaches available.

Dynamic Mail Forwarding Based on Superscription Table

Client asked this morning if we can provide a subscription service whereby:
Mail arives to a specific address on a cloud mail server with no procmail/maildrop possibilities
Cron runs Perl or PHP script on another server which checks for new mail and based on address mail purports to be from, does a subscriber look up, and forwards the email with any attachments to all subscribers along with an added unsubscribe link
Script deletes forwarded email
Mail server will have both IMAP and POP access, apparently.
// EDIT
Note that mail will be from 220+ governmental agencies/organizations. Users will use interface to specify which organizations they wish to receive forwards from. In order to run like a traditional mailing list we'd have to set up 200 mailing lists and then make an interface to handle subscriptions. The proposed interface will allow 1 - 200 subscriptions with a single opt-in confirmation email and a single opt-out interface.
// END EDIT
Client has been warned that header spoofing is child's play and that viral attachments are a serious concern and is willing to proceed nonetheless.
So, with the caveat that this is NOT an idea that I endorse what libraries have you used to accomplish this sort of task?
You do not mention what kind of mail server you are dealing with. Perl has Net::IMAP::Client and Net::POP3 to handle fetching mail.
For sending email using an SMTP server, there is Email::Sender or Net::SMTP or Net::SMTP::SSL.
At a minimum, you'll need an email account which you can use to send emails (this might be the original account that receives the messages).
In between fetching and sending, you can check for spam using Spam Assassin and for viruses using ClamAV.
I don't know why the original messages need to be deleted, but at the very least, I would log every single step in detail.
What you're describing is a mailing list. If at all possible, you should look into using one of the several existing software packages designed for managing such lists, such as majordomo, ezmlm or mailman, rather than trying to roll your own.

how to save gmail emails accordingly in database

i want to have a script that will save gmail emails from an account in mysql db using php. Mails(both freshly new and reply ones) will be marked to be in the same category if they have the same subject. That is just the same way in gmail or yahoo mail.
So far as I know gmail IMAP does not give the facility to track which are the reply mails.
Which API or whatever should I use??
The script will keep running.
Do I need to use scheduled task for that?
I haven't worked with that, but as i Google around, it turns out GMAIL provides IMAP Extensions API. And there you have an option to Access to the Gmail thread ID: X-GM-THRID
The reply emails as you call them are stored in the sent-mail folder, so just download them with IMAP.
You can track how emails go together using the In-Reply-To: and References: headers. Using the subject is not reliable.
#sof_user : every mail will have message_id in the header. google tracing the email with the id, if it is reply, then IN-REPLAY-TO will have the same id.

Categories