Sending email

Questions and discussion about The WiPy 1.0 board and CC3200 boards.
Target audience: Users with a WiPy 1.0 or CC3200 board.
henkoegema
Posts: 4
Joined: Sat Sep 01, 2018 3:24 pm

Re: Sending email

Post by henkoegema » Fri Sep 28, 2018 2:07 pm

I'm trying to use the examples in this thread to send e-mail from a Wemos D1 mini ESP8266 loaded with micropython.

It already fails at the first line: >>>import smtplib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: no module named 'smtplib'

Q: how to import module smtplib ? (or module curl ?)

henkoegema
Posts: 4
Joined: Sat Sep 01, 2018 3:24 pm

Re: Sending email

Post by henkoegema » Mon Oct 01, 2018 11:51 am

[quote=henkoegema post_id=30530 time=1538143662 user_id=4304]
I'm trying to use the examples in this thread to send e-mail from a Wemos D1 mini ESP8266 loaded with micropython.

It already fails at the first line: >>>import smtplib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: no module named 'smtplib'

Q: how to import module smtplib ? (or module curl ?)
[/quote]

I made small progress. :)
After downloading from: https://github.com/micropython/micropython-lib I could import smtplib. (but not module curl)

I'm trying this example:
*********************************************************************************************
>>> import smtplib
>>> efrom = 'me@yahoo.com'
>>> eto = 'you@gmail.com'
>>> header = 'To: {} \nFrom: {} \nSubject: Email from my WiPy\n\n'.format(efrom, eto)
>>> msg = header + 'Hi,\nThis is the WiPy emailing ;-)\n'
>>> smtpserver = smtplib.SMTP('smtp.mail.yahoo.com', 465) <--------------------- :roll:
>>> smtpserver.helo()
(250, b'smtp.mail.yahoo.com')
>>> smtpserver.login(efrom, 'ypassword')
(235, b'2.0.0 OK')
>>> smtpserver.sendmail(efrom, eto, msg)
{}
>>> smtpserver.close()
***************************************************************************************************

Here it fails:
>>> smtpserver = smtplib.SMTP('smtp.mail.gmail.com', 465)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'SMTP' <--------------------- :roll:

henkoegema
Posts: 4
Joined: Sat Sep 01, 2018 3:24 pm

Re: Sending email

Post by henkoegema » Mon Oct 01, 2018 11:54 am

[quote=dhylands post_id=6055 time=1445443348 user_id=81]
I know you can send emails using just telnet (http://www.yuki-onna.co.uk/email/smtp.html) so you should be able to do it without smtplib.
[/quote]

http://www.yuki-onna.co.uk/email/smtp.html

Not Found
The requested URL /email/smtp.html was not found on this server.

User avatar
vdb_peter
Posts: 7
Joined: Mon Feb 11, 2019 12:51 am
Location: Melbourne

Re: Sending email

Post by vdb_peter » Wed Jul 15, 2020 5:39 am

While this thread was helpful in getting SMTP email working on the ESP8266, I found this (hopefully will help others): https://blog.thepodnet.com/sending-mail-using-nodemcu/

To make it work with Hotmail (gmail got too hard with their "insecure" login controls), I had to add an extra "\n" after the Subject line.

If the link disappears, I'll send his code.

Post Reply