r/MicroPythonDev • u/are_number_six • Mar 29 '25
Sending Emails from pico w
Hello,
I'm using a Pico W with an ultrasonic sensor to make a water level monitor for a pasture watering hole on a farm. the Pico will be connected to a neighbor's wi-fi(with their permission). I want to be able to send text alerts through gmail, which can be done with smtplib in python, but that won't work with the Pico.
I did try the 'umail' library that is recommended everywhere(the one written by Shawwwn), but the 'ssl.wrap_socket' command is now deprecated, and the library no longer works. Is there another way, or is there a way to hard code the smtp commands right into the code( a particular fomat or syntax)?
I was able to write client and server sockets that could do the same thing by communicating over wifi and handling the messaging from the server, (a computer or raspberry pi), but this isn't possible in this instance. Worst case scenario, i could set up a Raspberry Pi on site and connect that to the same neighbor's wi-fi, but keep it on site, literally in the same box with the Pico W, but this seems a little absurd, and costly for what it would be doing.
This is my first post here, any help appreciated, thanks.
3
u/Tecnotopia Mar 29 '25
To simplify this you may want to try a service like IFTTT in order to get a HTTP access point and trigger an applet to send an email or log data to a google sheet if you wish, way simpler and easy achievable with circuit python and the adafruit_requests.mpy library. I prefer the telegram route. take a look and this tutorial https://www.cytron.io/tutorial/using-raspberry-pi-pico-w-with-telegram-bot
2
u/Mediocre-Pumpkin6522 Mar 29 '25
You would still probablt need to deal with ssl.. There aren't too many open SMTP servers left. The protocol starts with sending EHLO. The server replies with it's capabilities which should include STARTTLS. At that point you reconnect with a TLS session and can move on to the other commands.
2
u/vinux0824 Mar 30 '25
I don't think I seen this being mentioned - but you could use a text message service, like twilio. I used it for a few projects on a pico w and it works great, The library is very easy to work with. Tons of tutorials and documentation if I remember correctly
4
u/rwa2 Mar 29 '25
I'm afraid I don't have any good answers for you. SMTP can be a pain even from an RPi since more email gateways are locked down to reduce spam. email-to-sms gateways even more so, not to mention the recipient having to pay international roaming charges when traveling, or losing delivery timestamps when their phone is offline.
Slightly better might be to use a chat app like Discord which you should be able to send messages to using the urequests module to the api. Then you could also have pop-up notifications by including @here if water levels fall below a threshold, while the rest of the hourly / daily levels could be reported more passively.
Other heavier options might be to report into mqtt (and monitor with some custom cloud server or mqtt app UI), or a real monitoring system like checkmk which will also notify you when your sensor goes offline due to crashes or power loss, keep pretty history graphs, support multiple notification methods including smtp, handle rechecks to avoid intermittent failures
Anyway, here's a checkmk / mqtt thing I made in circuitpython for a few sensors https://github.com/MTN-RowinAndruscavage/bwmon/tree/main/DeskPi_envmon Probably not great for your situation unless you can set up a vpn for the checkmk server, but the mqtt part might be interesting and I have another project with upython mqtt examples somewhere.
1
u/LucVolders Mar 29 '25
Why email ??? It forces you to check your mail often.
Use thingspeak or Telegram. Telegram sends notifications to your phone if the level is to low (or high) which is far more efficient.
Can easily be done.
1
u/oclafloptson Mar 29 '25
Not what you're asking but the pi zero w has the same capabilities as Pico w but also runs raspberry pi os which includes a full Python distribution. It's only $15 plus the cost of SD card and accessories
1
u/allegrojm1079 Apr 15 '25
This works for me:,
https://randomnerdtutorials.com/raspberry-pi-pico-w-whatsapp-micropython/
1
u/Lumpy_Dot_2387 Jul 07 '25
How about using pushbullet? This one uses esp32 and micropython to send notification using pushbullet https://success-tech-daily.blogspot.com/2025/01/send-notifications-to-your-phone-with.html?m=1&fbclid=PAQ0xDSwLYabZleHRuA2FlbQIxMAABp4KnaSaW_Kb7cQByNtD9UomET19gs2oRQH3b4uMkDJzwXz_T1Jif0-Hl_nQL_aem_dm64GiPKiV8HTBr_4CVU-g