Connecting to Gmail SMTP

Following this tutorial…

Ralph’s code is here:

Trying to use the Gmail part of this for sending mail via a sensor event on an Argon. I already have working Argon code for the sensor part. I’ve already explored Mailgun and using PHP scripts to send email. Looking for a different method.

I found a Base64 library in Particle, but running into issues with the rest of the code, particularly with the client commands. My Argon is already on my network, so I know I can strip out that piece from Ralph’s code. So this library shouldn’t be needed:

#include <ESP8266WiFi.h>

This line also presents problems if the ESP8266WiFi.h isn’t present:

WiFiClientSecure client;

Again, I’ve already explored Mailgun and using PHP scripts to send email, and those have been successful but have some downsides. With Mailgun, the messages arrive in a spam folder, which is not useful. Calling a PHP Script is better, but I am seeing a lot of false positives, possibly because the script is exposed on my server. Looking for a different method, that is not exposed, preferably secure. thus the attempt at Gmail.

The Particle platform doesn’t implement TLS/SSL encrypted TCP connections (WiFiClientSecure) and I’m pretty sure gmail will not allow you to send your password in clear text over non-encrypted SMTP (port 25).

The way I would do is have your server code triggered by a webhook to generate the email. This can be made secure by having your server implement TLS/SSL and having the webhook include a secret pre-shared key in a header field, which prevents other servers from being able to interact with your mail sending server.

1 Like

on this line, you can use Ubidots STEM, 3 free devices and I believe you can send some emails for free.
Options that bring some cost:

  • webhook plus integration with TWILIO.
  • Ubidots full service


1 Like

Ralph talks about port 25 but doesn’t use it. He uses port 465. I’ve since also seen that Google has shut down less secure connections like Ralph shows there. But someone has worked out a way to get around that.

I have done this from a Particle device back when there was an active IFTTT integration, and you can do it now by using a webhook to trigger IFTTT. Basically as @rickkas7 says you use your own server, but “your server” can be IFTTT.

You do have to give IFTTT your gmail credentials (well technically they don’t have your password, but you login and give them permission and IFTTT stores a token that allows it to work).

Be careful what you do with this! It is shockingly easy to generate a lot of email pretty quickly when things so south. Also once IFTTT moved to a paid subscription model, I have moved away from it for my own usage, but that is a personal choice. They still have a free tier for you to explore.

1 Like

This is something I have solved with Zapier in the past, but it does require a paid plan with them ($19.99/mo). They have an article on the topic here: How to send an email from a webhook | Zapier

You would just need to set up a Particle.publish() and a webhook subscribed to your published topic that outputs to Zapier. I’ve set up similar systems that send SMS from a webhook in 30 minutes or so.

I personally find Zapier an excellent tool for this sort of simple automation. There’s a ton of more advanced stuff you can do with their paid plans, and I find it easily pays for itself in the time I save setting up automations.


This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.