I have started writing an email program that is fully automated. The intent is to let people send emails and text messages to any email address at my domain and get a reply that is appropriate to their message.
For instance, if you were to send “hidden” (not in quotes) to “firstname.lastname@example.org, you would get a reply telling you about a hidden puzzle.
This program is, as the previous paragraph suggested, for a puzzle race. For anyone who doesn’t know about puzzle races, they are games people play where they must solve some sort of puzzles and do that while on a sort of scavenger hunt. There are many forms and styles to these games or races so look it up in you need for information.
I have participated in two events, both run by Outdoor Outreach in San Diego, CA. These were a lot of fun and one of the features of the events is the requirement to use a cell phone or other messaging system during the event. A puzzle may have an answer that is “text number of steps to jeff” which would require the participant to send a text message to email@example.com and wait for a reply. The reply might then say “what color are the steps?” and the answer to that question is the answer to that entire puzzle.
The event staff can also send out hints of all teams are having trouble somewhere.
I started with source code for both the POP3 protocol and the SMTP protocol. The sources were minimal and handle only client-side message handling. The SMTP code was written by me and the POP3 code was obtained from the Code Project online and then fixed to com,pile and run properly. There were minimal bugs and they are not worth mentioning.
The program is a Windows MFC based program using a main window and nothing else for a graphical user interface. All configuration information is read from XML files of my own design. The main window shows status messages.
<autoemail> <servers> <smtp server="smtp.1and1.com" port="587" user="******" pass="******"/> <pop3 server="pop.1and1.com" port="110" user="******" pass="******"/> </servers> <responses> <response sentto="GLUBGLUB" code="CODE"> Respone from glubglub because you sent "code". </response> <response sentto="GLUBGLUB" code="*"> Your glubglub answer is wrong! Sorry. </response> <response sentto="HELP" code="HIDDEN"> Look for the hidden puzzle near a large mooooo. </response> <response sentto="REGISTER" code="XYZ" action="special"> You have been registered. You will receive broadcasts and hints at this number/address until you "UNREGISTER". </response> <response sentto="UNREGISTER" code="*" action="special"> You have been unregistered. You will no longer receive broadcasts or other messages at this number/address. </response> <response sentto="BROADCAST" code="*" action="special"> Your message has been forwarded to all registered sender. </response> <response sentto="*" code="*"> Your message was not recognized. </response> </responses> </autoemail>
The program firsts reads the configuration information, as seen above, and verifies that the email servers are accessible. A thread is created and it loops continuously until the program is closed or until an error occurs that make further processing meaningless. Within this loop, the code checks for configuration file changes and then gets all of the emails on the POP3 server. For each email, the content is parsed to get the plain text of the email. The destination title, such as the “jeff” in “firstname.lastname@example.org” is used, as well as the first word of the email content, to find a response in the set of preconfigured responses. The XML configuration file holds those responses. Wildcards can be used in the configuration file and the last response in the file has ‘*’ for the destination name and ‘*’ for the email word to match. That way, the generic unknown response can be written in the file and doesn’t need to be in the source code.
I’ve also just added code to handle special actions. The XML file response entries can have an attribute that says that the code should take a special action when it sees the given destination name. Sending an email to “email@example.com” will tell the program to write the senders return address into a file for later use. There is also an “unregister” action and a “broadcast” action. The broadcast feature causes the sent email plain text content to be then sent to every registered user.
There have been no tricks or fancy code so far. Here are some details worth mentioning because they represent compromises I made in the design of this program.
- I used an XML code library that I wrote that is so insanely simple that it cannot be used to write XML and can’t handle any XML formatting that is not exactly what I expect to see. That example configuration file works but that’s about all that I can handle. It’s a very small amount of code which is a good thing.
- The POP3 and SMTP libraries cannot handle encryption of any sort. Passwords are mostly visible as they are transmitted. This is actually the case for so many email servers and clients that it’s not worth worrying about.
- This program relies on POP3 and SMTP. I could have had a dedicated server with a static IP address running as a mail server but that seemed like overkill. Uisng someone elses mail server and accessing it with SMTP and POP3 protocols is much easier.
- I chose Windows because that is the operating system I have on most of my computers. Plus, I may want to add more GUI code in the future and I don’t want to use QT or X-Windows.
I’ll write up some more as I find interesting issues worth mentioning. I might also write more details about what I have now but I’m not sure yet if that’s useful to anyone or to me.