Software apps and online services
Sometimes IoT projects need to send email notifications when a triggering event occurs. Devices that lack integral cloud connections require multiple hops and lots of links to achieve a simple email communication. Not only is this a number of different connected accounts to set up but the event-to-delivery time can take several minutes or more. Using the Arduino WiFiClientSecure library, a SendGrid API account, and Gmail, we can reduce that delivery time to mire seconds.
SendGrid is a major email sending service that boosts billions of emails sent per day. They offer a free account (100 per day limit) that's just right for most small projects. Create your account by signing up at their site for a free trial. Once you are confirmed and activated, create an API Key for this project. Paste this key value into the code where shown. The actual email message is JSON formatted with all of the necessary fields shown. You will need to put your email address in and adjust the subject and message to suit your notification.
The coded project in the section below is a complete working example that needs to be modified for your wifi credentials and API Key. Compile and load into a Feather Huzzah or other ESP8266 board using the Arduino IDE. Be sure to open the serial monitor window to see the results of your test. Once satisfied with the results, integrate the code lines into your actual project.
The SendGrid API will send to any valid email account. If you use Gmail, and the Gmail phone app, you can get notified in seconds of the event happening. This is because Gmail will push the email to the phone. Other accounts that use a polling method will pull the emails to the phone so the update time is based on that polling rate which is usually 15 minutes or longer.
I wanted a very simple way to get an email notification, and I think this small amount of code does exactly that. It's really bare bones, so feel free to augment and improve.