I'm working on email messaging / tickets system.
Logic:
Client starts new ticket on website, which is stored in database
I'm getting email about new ticket in my inbox (generated by website, with unique ID in subject line)
Replying email (reply-to email address e.g. tickets#example.com)
PHP cron script reads inbox, getting all messages, storing them to database and generating email to client.
Client replies to email (reply-to email address - tickets#example.com with ID in subject line)
Question:
How I can read where is new reply text and old one from email? Email with reply example:
Envelope-to: tickets#example.com
From: client#example.com
To: tickets#example.com
Subject: Re: New Ticket: "Project #1" (ID: 15)
Message-ID: <70c4e4c182e6eb10c0e45feefa4ce9cg#example.com>
This is reply to message.
On 2014-05-13 09:04, Client wrote:
> This is text
>
> ----
> Best Regards,
> Client
I need to have only latest reply. Client can write reply on bottom or on top (anywhere to be honest), with any mail client, and I bet - a lot of mail clients have different formatting..
Any suggestions?
If I would need to solve this question, I would be using some kind of 'diff' system. I don't' know if that exists for PHP, but I'm confident it does.
So then more technical, if you have a way to diff the mails. I would take the original mail without the header (let's call it mail A), and also the new mail without the header (mail B). Then it's as easy as comparing mail A with B and see what the difference is. The lines that were added, are the response of the user.
Some things you will have to look for yourself, because I don't know an answer for them at this moment:
What if the user doesn't send the original message? You could for example only use the lines that were added from your diff, not those which were deleted.
What if the user changes something inline in your response? I have no idea how to solve this.
My solution would actually be to don't give the users that much freedom. Just prepare a place where the users should write their message. Something like: "Write your message between the following lines <line> <line>", or "<line>Write your message above the previous line". Then you know where to look for the text.
The more freedom you give, the more difficult it becomes for you. You can start with an easy system, and gradually improve the intelligence of the system. That's how I start most of the time: start from something simple and increase the difficulty gradually.
Related
I have a database that contains 20K of what the email I was sending newletter The problem I found was that each of the email I sent back type
Delivery Status Notification (Failure)
I am willing to transfer this email which is inactive knowing that I filter all email from the standpoint of the field formatting and existence.
as I have to see how little research has addressed this problem I find the notion that bounces are already implemented on the software.
If any one has any That a idea how I can apply that bounces in the php will be welcome
cordially
Well, it's pretty hard to understand what are you talking about, but...
As you mentioned, when e-mail can't be delivered (for many reasons) you will get Delivery Status Notification which will goes to inbox of e-mail that you used to send the message.
For example, if you send newsletter from newsletter#test.com to customer#test.com and the message can't be delivered then you get notification at newsletter#test.com. So just open your newsletter#test.com inbox with php, read the messages, parse them, and save the errors (if occurs) in database, matching by e-mail.
This link could be useful:
http://php.net/manual/en/function.imap-open.php
If you have your mailbox at your own server then the thing is much simpler, because all you need to do is to make ln, and then just open the file to parse.
ln -s /var/mail/my-inbox /var/www/my-script/inbox
I am building a basic support request system where the customer can log in and ask a question and an admin can go in and reply and it will set the status to "Responded" and e-mail the customer to let them know someone has responded.
My question is.. I have a "comments" section which is a log of the interaction between the admin and the customer. If I e-mail the customer the initial response from the admin, then I have a feeling they will just hit "Reply" from their email and start communicating through there, and the logs won't be stored.
I could either e-mail the customer and say "Log in to view the response", or maybe if the customer does hit reply I can somehow track it and insert that in the comments table like they did it from the website. If that is even possible?
Just wondering if there is a standard way to do this and any suggestions you may have.
Thanks!
When sending the email to the user you can have it sent from an email address created for that specific ticket. Something that can identify it with your email system to help you route it back to the php ticketing system.
support(ticketnumber)#domain
support12345#mydomain.com
Then it depends on your email server how to go from there.
There are several useful tips at this question that may help or get your started.
How to get email and their attachments from PHP
If you want their reply to be automatically inserted into the DB, you'll have a assign a cron job in your server to run a php script to detect whether there's a reply from a customer (you need a table listing the customers' email and names.
Each time a customer uses the ticket system their email and name goes into this table).
You'll need to connect to your Inbox too via imap or SMTP, and there are scripts to do this (phpmailer, swiftmailer, etc) and "walk" through each email and see if the sender email matches any in your customers table. Then so an INSERT to the comments table.
Anther way is to read through the emails each time the comments page is loaded, but this will cause the page to take longer to load. However, the data will always be more "real-time" compared to cron jobs.
You could use email piping (if your server supports it).
In the subject, you'd have a unique identifier which contains the ticket ID or something unique to the ticket. Example: "How do I eat food [Question: #1234]", where 1234 is the ticket ID.
In your control panel, you would set up an email forwarder to your email piping script.
This tutorial offers the basics to email piping, and I used it as the base for my piping script: http://www.damnsemicolon.com/php/parse-emails-in-php-with-email-piping-part-1
I am not sure if it is in the headers or not, but I am looking for a way to tell if an email I receive is a response to an email I sent, and if so, to only grab the new text, not "quoted text"
A little background: I am creating a script that will send out emails automatically. I am creating a cron job to run at periodic intervals to check to see if there were any replies. If there were replies, I only want to grab the new stuff, and not the old stuff.
In the past, I would send out emails with the id in the subject (You have a new response [1234]), and would then check the subject for the stuff in between the [ and ]. Then I would grab all the message and store it since every web browser/email uses a different character or style for quoted-text. Some do ">" some do a horizontal rule, some do absolutely nothing.
Anyways, I am just looking for something in the email header that would indicate they are replying and what the new text might be. If it's not possible, I will just keep on doing what I am doing.
You can know if an email is the reply of another email or not by using the combination of In-Reply-To and References.
Every email has a unique ID in its header called Message-ID, according to this RFC 1, you can track the ancestors of any email.
I have checked it and it is working in all clients (Outlook, Thunderbird)
I will give an example to use.
1- In the header of the email you send for the first time, you (your mail server or you in code) send an ID (Message-ID), if you open source of the email you will see it like this in top section:
... // You (your code) send:
Message-ID: <1#your-domain-mandatory.com>
...
You just need to keep this Message-ID in your program. any subsequent reply will refer to this ID.
2- Client will reply email 1 to you. Client will send a crucial header for you to tell you for which email this reply is in addition to its own Message-ID.
... // Client(Thunderbird) send:
Message-ID: <2#your-domain-mandatory.com>
In-Reply-To: <1#your-domain-mandatory.com>
...
When you receive the second email, it will be easy for you to keep track of the previous email you have sent because the ID of mail(1) is in the In-Reply-To header of the mail(2).
3- if you want to reply back this email again inside your code, you just need to put the Message-ID of the mail(2) in In-Reply-To header and Message-ID of mail(1) and mail(2) in References header. So the client will understand the chain correctly.
... // You (your code) send:
Message-ID: <3#your-domain-mandatory.com>
In-Reply-To: <2#your-domain-mandatory.com>
References: <1#your-domain-mandatory.com> <2#your-domain-mandatory.com>
...
By this header, you are telling the client that this email is a reply to the mail(2) and the ancestors are mail(1) and mail(2).
I have worked with them and read about them and it is working, my problem now is to just get the text of the last email and not the quoted text from the replies. (we are running our own Ticketing system, we create a comment for each email)
Unfortunately, e-mail clients can essentially do whatever they want with your message, and there is no reliable standard for determining how a received message originated at the client. In addition, IMAP doesn't really have anything to do with it. E-mails can be sent a number of different ways, including webmail.
The best you can do is look for an ID number in the subject line (assuming folks don't change it, which they rarely do). You can also do what Google does... fuzzy match the reply text to e-mail you sent to that address. If it matches, consider it part of the reply. This takes great effort though.
I am writing an app to let users reply to a post or thread straight from their email similar to Facebook. Users can already add new posts via email and it is working fine.
When a new post is generated an email alert is sent to specific users and a unique reply address is created containing an encoded string with the original post/thread ID. This is working fine. The emails are sent and the system picks up the reply using the unique reply address.
My problem is trying to isolate the comment/reply in the email, from the quoted original email underneath. Here is an example of an email body received:
reply text
(Origional Email Header)On 10 March 2011 16:35, Example SIte
<pwKVb1BVUITY4Ai-fKR8ioPrR8Zki9cKBmAA0njXi8Y#example.us= > wrote:
I have thought of using identifying characters or strings but each email provider displays the original email in a reply differently.
Does anyone have any ideas how I can isolate the reply text from the original email's header and body?
Thank you,
Chris.
For a support ticket system I wrote, I focused on using the References email header concatenating previous message ids onto that. Many systems will hold onto that, but, of course, not all. Plus, my system is organic, ie, attempts to process emails with any subject and body in less of a controlled environment. A work in progress.
Since different email servers are going to format headers differently in replies, I don't think there is any way to reliably catch all of them. But if you're dealing with a relatively small number of users, you can just use regex matching to catch some of the most common header formats and strip those.
I would like to know what's the best way to manage answers to email notifications.
eg. The user receive an email notification, and instead of having to click on a link to go on the website and answer it he could directly reply to the email.
There's no best way. Depending on what you want to do with the responses, you could as well handle them with thunderbirds message filters ;) .
Put a unique identifier into the subject or the body of the notification that you're sending so that you can identify & classify the email correctly when a user replies by email.
If you want to stick with php: pick up the php pop3 client class from: http://www.phpclasses.org/browse/package/2.html or find a client elsewhere and then just parse your message responses and classify / handle them however you want to.
Use the Message-ID header field to uniquely identify each message. If there is a reply on that message, the client should put that message ID in the In-Reply-To header field in the reply message. See RFC 2822 for further details.
Stick an id and authentication token in the subject line.
Pipe it into a script that can process it with Procmail
As a learning exercise you could read the php code and Documentation to the drupal module http://drupal.org/project/mailhandler mail handler. This accepts emails and looks for script like instructions.
The answer above about checking the message id is also very valid.