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 ?)
Sending email
-
- Posts: 4
- Joined: Sat Sep 01, 2018 3:24 pm
Re: Sending email
[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) <---------------------
>>> 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' <---------------------
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) <---------------------
>>> 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' <---------------------
-
- Posts: 4
- Joined: Sat Sep 01, 2018 3:24 pm
Re: Sending email
[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.
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.
Re: Sending email
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.
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.
Re: Sending email
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
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 4794 times
Last edited by vdb_peter on Tue Sep 08, 2020 6:47 am, edited 1 time in total.
Re: Sending email
Thanks for posting. Didn't work on my Hotmail account but adding the lines:
... got me the subject line I needed in my working Gmail(no 2step auth) version .
Appreciate you taking the time to post.
Dave
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
Appreciate you taking the time to post.
Dave
-
- Posts: 463
- Joined: Wed Apr 08, 2015 5:19 am
Re: Sending email
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...