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: 8
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.

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

Re: Sending email

Post by vdb_peter » Wed Aug 12, 2020 4:42 am

Seeing this link https://blog.thepodnet.com/sending-mail-using-nodemcu/ has disappeared, here's his code (Not mine).

This works with Hotmail (and derivatives) with the attached "umail.py".

Updated 8/9/20: https://github.com/shawwwn/uMail

Code: Select all

import umail
smtp = umail.SMTP('smtp.live.com', 587) #
smtp.login('<email>@hotmail.com', '<password>') # Your login, and password in clear text
smtp.to('<email>') # Full email address of recipient
smtp.write("From: Joe Blogs <j_blogs@hotmail.com>\n") # This is just a string
smtp.write("To: John Doe <j_doe@hotmail.com>\n") # This is just a string
smtp.write("Subject: This is Test\n")
smtp.write("\n") # This line is essential
smtp.write("Yay!\n") # 1st line of email body
smtp.write("It's Working\n")
smtp.write("...\n") # This line is essential
smtp.send()
smtp.quit()
Attachments
umail.zip
A usocket based email module
(1.38 KiB) Downloaded 41 times
Last edited by vdb_peter on Tue Sep 08, 2020 6:47 am, edited 1 time in total.

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

Re: Sending email

Post by davef » Wed Aug 12, 2020 7:24 am

Thanks for posting. Didn't work on my Hotmail account but adding the lines:

Code: Select all

smtp.write("Subject: This is Test\n")
smtp.write("\n") # This line is essential
smtp.write("Yay!\n") # 1st line of email body
smtp.write("It's Working\n")
smtp.write("...\n") # This line is essential
... got me the subject line I needed in my working Gmail(no 2step auth) version .

Appreciate you taking the time to post.
Dave

SpotlightKid
Posts: 420
Joined: Wed Apr 08, 2015 5:19 am

Re: Sending email

Post by SpotlightKid » Tue Aug 18, 2020 8:32 pm

The RFC prescribes that all lines in a message must end with CR + LF (i.e. '\r\n') not only a single line-feed. Most mail clients and server tolerate line-feed-only line endings, though, but...

Post Reply