views:

484

answers:

8

A number of applications have the handy feature of allowing users to respond to notification emails from the application. The responses are slurped back into the application.

For example, if you were building a customer support system the email would likely contain some token to link the response back to the correct service ticket.

What are some guidelines, hints and tips for implementing this type of system? What are some potential pitfalls to be aware of? Hopefully those who have implemented systems like this can share their wisdom.

+2  A: 

You can set the address that the email is sent from, what will be put into the To: address if someone just presses 'Reply-to'. Make that unique, and you'll be able to tell where it came from, and to where it must be directed back to.

When it comes to putting a name beside it though '"something here" [email protected]' - put something inviting to have them just reply to the mail. I've seen one major web-app, with Email capturing that has 'do not reply', which turns people off from actually sending anything to it though.

Alister Bulman
It seems the unique reply-to approach assumes a fair amount of flexibility with your mail server setup. Maybe others can chime in on experience with this approach as well as alternatives if you have limited control over your mail server. Or maybe I misunderstand the requirements for this approach.
Larsenal
you do need some control - or at least the right mail server running. Postfix, for example allows for '+ addressing', so that [email protected] goes to the same account as [email protected]. Even just reading from the POP3 account that would land in, would give the unique reference.
Alister Bulman
+1  A: 

EDIT: I misunderstood your question.

You could configure your email server to catch-all, and generate a unique reply-to address. E.g. [email protected].

A polling process on the server could read the inbox and parse out the relevant part from the received email, CS-2343434 could mean Customer Support ticket ID no. 2343434.

I implemented something like this using JavaMail API.

Just a thought.

karim79
This isn't exactly the type of thing I'm talking about. I'm thinking of clicking "Reply" in Outlook and having your app slurp in the email response. Your answer just illustrates the idea of embedding meaningful, specific URLs in the email message.
Larsenal
+2  A: 
RossFabricant
A: 

Bose has a pretty great system where they embed a Queue and Ticket ID into the email itself.

My company has the traditional Case # on the subject line, but when CREATING a case, require a specific character string "New Case" "Tech Support Issue" on the subject line to get through the spam filters.

If the email doesn't match the create or update semantics, the autoresponder sends an email back to the recipient demonstrating how to properly send an email, or directs them to our forums or web support site.

It helps eliminate the spam issue, and yet is still accessible to a wide technical audience that is still heavily email dependent.

Chris Kaminski
A: 

Spam is going to be a bit of a concern. However since you are initiating the conversation you can use the presence of your unique identifier (I prefer to use the subject line - "Trouble ticket: Unable to log into web...[artf123456]") to filter out spam. Be sure to check the filter on occasion since some folks mangle the subject when replying.

Chris Nava
+9  A: 

Some guidelines and considerations:

The address question: The best thing to do is to use the "+" extension part of an email (myaddr**+custom**@gmail.com) address. This makes it easier to route, but most of all, easier to keep track of the address routing to your system. Other techniques might use a token in the subject

Spam: Do spam processing outside the app, and have the app filter based on a header.

Queuing failed messages: Don't, for the most part. The standard email behavior is to try for up to 3 days to deliver a message. For an application email server, all this does is create giant spool files of mail you'll most likely never process. Only queue messages if the failure reasons are out of your control (e.g., server is down).

Invalid message handling: There are a multiple of ways a message can be invalid. Some are limitations of the library (it can't parse the address, even though its an RFC valid one). Others are because of broken clients (e.g., omitting quotes around certain headers). Other's might be too large, or use an unknown encoding, be missing critical headers, have multiple values where there should only be one, violate some semantic specific to your application, etc, etc, etc. Basically, where ever the Java mail API could throw an exception is an error handling case you must determine how to appropriately handle.

Error responses: Not every error deserves a response. Some are generated because of spam, and you should avoid sending messages back to those addresses. Others are from automated systems (yourself, a vacation responder, another application mail system, etc), and if you reply, it'll send you another message, repeating the cycle.

Client-specific hacks: like above, each client has little differences that'll complicate your code. Keep this in mind anytime you traverse the structure of a message.

Senders, replies, and loops: Depending on your situation, you might receive mail from some of the following sources:

  • Real people, maybe from external sources
  • Mailing lists
  • Yourself, or one of your own recipient addresses
  • Other mail servers (bounces, failures, etc)
  • Entity in another system ([email protected], system-monitor@localhost)
  • An automated system
  • An alias to one of the above
  • An alias to an alias

Now, your first instinct is probably "Only accept mail from correct sources!", but that'll cause you lots of headaches down the line because people will send the damnedest things to an application mail server. I find its better to accept everything and explicitly deny the exceptions.

Debugging: Save a copy of the headers of any message you receive. This will help out tremendously anytime you have a problem.

--Edit--

I bought the book, Building Scalable Web Sites, mentioned by rossfabricant. It -does- have a good email section. A couple of important points it has are about handling email from wireless carriers and authentication of emails.

Richard Levasseur
A: 

Email is a cesspool of bad standards and broken clients. You need to be prepared to accept almost anything as input. You will need to be very forgiving about what kinds of input are tolerated. Anything easy for you to program will likely be difficult for your users to use correctly. Consider the old mailing list programs that require you to issue commands in the subject line. Only hardcore nerds can use those effectively. And some of those trouble-ticket CRM things you mentioned have bizarre requirements, such as forcing the user to reply between two specific text markers in the text. That sort of thing is confusing to people.

You'll need to deal with email clients that send you formatted text instead of plain text. Some email clients still don't handle HTML properly (cough GMail) so your replies will also need to be designed appropriately. There are various ways in which photos might be "uploaded" via email as well, especially when mobile phones are involved. You will need to implement various hacks and heuristics to deal with these situations.

It's also entirely possible that you will get email that is valid but unusable by the email parsing library you are using. Whether or not this is important enough to roll your own will be a judgement call.

Finally, others have mentioned using specific email addresses to uniquely identify a "conversation". This is probably the easiest way to do this, as the content of the mail will often not survive a round trip to a client. Be prepared, however, to get mail to old IDs from old customers who, instead of opening a new ticket somehow, reply to an old ticket. Your application will probably need some way to push emails with an old ID into a new case, either manually or automatically. For a CRM system it's very likely that a user would reply to an old email even if you already sent him a new email with a new ID in it. As for whether you should use [email protected] or just [email protected], I'd go with the latter because the plus-sign confuses some email clients. Make your IDs guids or something and have some way to validate them (such as a CRC or something) and you'll get less junk. Humans should never have to type in the GUIDs, just reply to them. The downside is spam filtering: a user's computer might view such email addresses as spam, and there wouldn't be an easy way to whitelist the addresses.

Which reminds me: sending email these days is full of pitfalls. There are many anti-spam technologies which make it extremely hard for you to send email to your customers. You will need to research all of these and you need to be careful, and do some testing, to ensure that you can reach the major email providers. A website like Campaign Monitor can help you if you are sending email.

Mr. Shiny and New
+1  A: 

The best way to achieve this will be to write a window service that acts like a mail client [pop3 or imap]. This windows service should execute a timed action triggered by a timer, which connects to the mail server and polls the server for any unread message(s) available in the email inbox. The email ID to check for is the email ID on which the users will give their input on/to. If the windows service client finds that there exists any new mail(s) then it should download and filter the email body and push further for processing based on the user input in the email. You can host the input processing in the same windows service but it is not advisable to do so. The windows service can put the inputs in a special application directory or database from where your main appication can read the user inputs received in email and process them as needed.

You will be required to develop a high performance TCP/IP client for doing so. I advise you not to use the default .Net library due to performance issues, instead use one of the best availabel open source TCP/IP implementations for .Net like XF.Server from kodart. we have used this in our applications and achieved remarkably grear results.

Hope this helps..

this. __curious_geek