ESP32 sending email

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
Tesla_X
Posts: 12
Joined: Thu Nov 12, 2020 10:54 am

ESP32 sending email

Post by Tesla_X » Thu Nov 12, 2020 11:08 am

Good afternoon. Wrote the code to a file BOOT.py so that ESP 32 sends an email when I click the button. At the same time, I preloaded the library smtplib.py. Just in case, I uploaded ssl.py, socket.py, re.py, io.py, hmac.py, email.utils.py, email.message.py, email.generator.py, email.base64mime.py.

Code: Select all

from machine import Pin
import smtplib

p4 = Pin(4, Pin.IN)
p0 = Pin(0, Pin.OUT)
p0.off() 

def email_send():
    fromaddr = '...@yandex.ru'
    toaddrs = '...@yandex.ru'
    msg = ("From: %s\r\nTo: %s\r\n\r\n"
           % (fromaddr, ", ".join(toaddrs))) + 'alarm'

    server = smtplib.SMTP_SSL('smtp.yandex.ru')
    server.login('...', '...')
    server.sendmail(fromaddr, toaddrs, msg)
    server.quit()

while True: 
        if p4.value() == 0:
            p0.value(1)
            email_send()
        elif p4.value() == 1:
            p0.value(0)
 


After running the script and clicking the button, it returns the error "Traceback (most recent call last):

Code: Select all

File" <stdin>", line 51, in <module>
File "<stdin>", line 39, in email_send
AttributeError: 'module' object has no attribute 'SMTP_SSL'"
Tell me what the problem is? At the same time, the script for sending a message to PyCharm works.

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: ESP32 sending email

Post by davef » Fri Nov 13, 2020 5:40 pm

Which modules did you import at the top of your file? Where did you get these files from?

I spent many hours looking for a SMTP implementation that would work with Micropython on the ESP32 board, eventually using uMail.

Tesla_X
Posts: 12
Joined: Thu Nov 12, 2020 10:54 am

Re: ESP32 sending email

Post by Tesla_X » Fri Nov 13, 2020 10:32 pm

davef wrote:
Fri Nov 13, 2020 5:40 pm
Which modules did you import at the top of your file? Where did you get these files from?

I spent many hours looking for a SMTP implementation that would work with Micropython on the ESP32 board, eventually using uMail.
Hello. Libraries with took with https://docs.python.org/3. The list of libraries: ssl.py, socket.py, re.py, io.py, hmac.py, email.utils.py, email.message.py, email.generator.py, email.base64mime.py.
Thanks for the tip. I'll try to use uMail.

kysodev
Posts: 6
Joined: Sat Apr 09, 2022 10:44 am

Re: ESP32 sending email

Post by kysodev » Sat Apr 09, 2022 10:51 am

davef wrote:
Fri Nov 13, 2020 5:40 pm
I spent many hours looking for a SMTP implementation that would work with Micropython on the ESP32 board, eventually using uMail.
Hi, I know this is an old thread but I figured since the last person didn’t respond after stating they would try uMail that it may well have worked for them. I’m currently having this issue now on an ESP8266 NodeMCU board that I’m trying to send an email from.

I have an smtp2go account and have successfully used this service via standard Python code but when trying to upload this or course, smtplib can never be found. I too came across uMail. Having real problems trying to implement it and not sure I’m doing it right.

I’ve tried to install it via pip, tried copying the source file “umail.py” onto my ESP8266, made sure I have got installed and updated pip and Python and found those were all fine. I keep getting hit with an error saying it can’t be found. Is there any chance you can check if umail is still working for your projects? Perhaps I’m implementing it wrong. (New to Python, primary language is Swift). Thank you.

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: ESP32 sending email

Post by davef » Sat Apr 09, 2022 7:40 pm

Looks like I have been using uMail for more than a year. I gave up on the ESP8266 as my programs were getting too big and trying to make frozen code for that device was beyond me.

Are you using pip on the desktop? There were some recent posts on Email attachments using uMail, which work well.

On the ESP32 I just copy umail.py from the Github account and use my own code for sending alarms and .csv files.

kysodev
Posts: 6
Joined: Sat Apr 09, 2022 10:44 am

Re: ESP32 sending email

Post by kysodev » Sun Apr 10, 2022 7:29 am

davef wrote:
Sat Apr 09, 2022 7:40 pm
Looks like I have been using uMail for more than a year. I gave up on the ESP8266 as my programs were getting too big and trying to make frozen code for that device was beyond me.

Are you using pip on the desktop? There were some recent posts on Email attachments using uMail, which work well.

On the ESP32 I just copy umail.py from the Github account and use my own code for sending alarms and .csv files.
Thanks, I'll have a look now. I was searching the terms "email", "smtp" and "umail" on the ESP8266 thread so will have a mooch around the ESP32 thread. And yes, pip on the desktop, not sure how else to use it if I'm honest. I've tried on mac and windows with no success. I made a new topic about it last night which should have more detail on what I've tried so far. (Just noticed you've replied on that thread too, again, I'll have a little look now in the ESP32 thread and hopefully can get past the "opening gate" :(

Post Reply