Is there a sketch that supports the receiving of email using the Arduino environment on the ESP8266? I can only find support for sending email. I know it's possible because the NodeMCU environment supports it. Any help is appreciated!
Once you know how to connect to any server and send messages to it, retrieveing emails is just a matter of sending right messages (=commands).
Here below follows an "IMAP tutorial", i.e. guide to which commands to send to an IMAP server to search and retrieve messages.
Note: once you connect to the IMAP server, the first command to send is the login command:
foo login user password
"foo" is just a session identifier, not a keyword. "login" is the keyword.
Once you get the welcome message, you can start sending more commands:
Select the proper folder:
. SELECT "INBOX"
Look for desired message (strings are always considered substrings, so no wildcards are needed):
. SEARCH FROM "email@example.com" SUBJECT "some keywords here"
This will result in list of matching messages, with search results formatted as follows:
* SEARCH 5 10 456
This means messages n.5, n.10 and n.456 match the query.
If examining just the subject (which may contain keywords and switch as required) is not enough, the whole body can be retrieved, both marking the message as read or leaving it untouched:
. FETCH 5 BODY[TEXT]
. FETCH 5 BODY[TEXT].PEEK
End IMAP session with:
For experiments from Windows using telnet:
telnet mailserver.domain.com 143