back

by dgellow·10y ago·view on hn ↗
Do you really know email protocols? I don't consider them simple.

For example take a look at the RFC 5322 and try to determine what is or isn't a valid address. You have a lot of weird edge cases to take in account and it's not always obvious how you are supposed to handle them.

https://tools.ietf.org/html/rfc5322#section-3.4

2 comments
If you need to support every possible way email can be sent and received (aka, you are building a generic email client), there is a lot of work you have to do.

However, if you are building a piece of software that simply communicates over email, you only have to support a relatively straightforward format for email that everyone else inherently supports.

Depending on the platform you're building on, a lot of the basics of actual email sending and receiving may be handled by the platform directly as well. I didn't have to write the SMTP handling for my code, for example, because the platform I was building my app on pretty much did it for me.

Also, the great thing about figuring out weird edge cases with email, is that email is such a widely used and universal protocol, there are literally millions of places on the Internet that have code for it or talk about it. There's a lot of resources out there.

Assuming I used python, I'd just import a library for sending email, or if using C# just import System.Net.Mail. Then it should be pretty simple. I would have made sure it worked for a major email provider (like gmail) and then work on edge cases when/if they came up.

Since the game would need your email password in order to load incoming messages I would advise them to create a new email just for game communication purposes anyway, and tell them not to use certain characters if for some reason I couldn't get them to work (although the libraries should be able to handle it anyway).

In fact, that's what I did for my SMTP. :) Though sadly, System.Net.Mail has no code for :receiving: mail, which is annoying. Also, System.Net.Mail doesn't work with Outlook.com, though it does work with Gmail (weird, right?).