Sending email with ESP32

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
SASM
Posts: 6
Joined: Thu Feb 08, 2018 11:28 pm

Sending email with ESP32

Post by SASM » Sun May 27, 2018 1:31 pm

I am using an ESP32 and trying to send emails through it. I am using the following code provided in this post viewtopic.php?f=11&t=1047&start=10

to = 'recipient@mail.com'
gmail_user = 'some.user@gmail.com'
gmail_pwd = 'password'
smtpserver = smtplib.SMTP("smtp.gmail.com", 465)
smtpserver.helo()
smtpserver.login(gmail_user, gmail_pwd)
header = 'To:' + to + '\n' + 'From: ' + gmail_user + '\n' + 'Subject: Email from the WiPy \n'
msg = header + '\n Hi, \n this is The WiPy emailing ;-) \n\n Cheers, \n The WiPy'
smtpserver.sendmail(gmail_user, to, msg)
smtpserver.close()

Also I am using the smtplib library provided there, the users there say it works, however I get the following error

Traceback (most recent call last):
File "<stdin>", line 19, in <module>
File "smtplib.py", line 84, in __init__
File "smtplib.py", line 110, in connect
AttributeError: 'module' object has no attribute 'IPPROTO_SEC'

Which basically happens when trying to create de smtplib.SMTP object. What is the problem here?

Jonwalter
Posts: 11
Joined: Mon Apr 09, 2018 12:41 pm
Contact:

Re: Sending email with ESP32

Post by Jonwalter » Wed Feb 27, 2019 4:21 pm

A bit out of date. But this question has been bothering me recently.
But it may help in the future. I hopemail is sent using the SMTP protocol. There are libraries and examples, and the basic protocol isn't too difficult to implement.

But it's not that simple, most SMTP servers won't accept mail from a simple SMTP client implementation. They require authentication and TLS encryption. That makes it harder.

Probably better to use MQTT, and let a cloud-based MQTT broker handle sending the email. I using best solustion for SMTP mailing here - https://www.atompark.com/smtp-service/

Regards Jonwalter

SASM
Posts: 6
Joined: Thu Feb 08, 2018 11:28 pm

Re: Sending email with ESP32

Post by SASM » Tue Nov 26, 2019 4:25 pm

It is completely fine. At the end of the day I managed doing it with services like IFTT. Either way thanks for the reply :D

Post Reply