Giter Site home page Giter Site logo

umail's Introduction

µMail (MicroMail)

A lightweight, scalable SMTP client for sending email in MicroPython.

Usage:

A bare minimal approach

import umail
smtp = umail.SMTP('smtp.gmail.com', 587, username='[email protected]', password='mypassword')
smtp.to('[email protected]')
smtp.send("This is an example.")
smtp.quit()

API docs:

  • umail.SMTP(host, port, [ssl, username, password])

    • host - smtp server
    • port - server's port number
    • ssl - set True when SSL is required by the server
    • username - my username/email to the server
    • password - my password
  • SMTP.login(username, password) If you did not login when intializing the server, do it here!

  • SMTP.to(addrs, mail_from)

    • addrs - Recipient's email address. If multiple recipents, use a list, eg. ['[email protected]', '[email protected]']
    • mail_from - manually specify the MAIL FROM address, default value is your smtp username. example
  • SMTP.write(content) To send a long email or an email that contains large attachments, you will most likely exceed the memory limit of your MCU.
    Use this function to break up your email into smaller chunks.
    Each call to write() will cause the current content to be sent to the server so you can load the next chunk.

  • SMTP.send([content]) Finish writing the email.
    Make the SMTP server to actually send your email to the recipent address.

  • SMTP.quit() Close the connection to the server

Other

For more details, pleasse refer to sample code under examples\

umail's People

Contributors

mtowara avatar shawwwn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

umail's Issues

uMail and adding ussl.py to ESP32-CAM

Good to see you are still around.

Trying to email a image obtained in the program:
https://github.com/shariltumin/esp32-cam-micropython-2022

Appears he didn't bake-in ussl so copied ussl.py from Micropython Github and get this error:

Camera ready?:  True
144540
STARTTLS OK
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "cam.py", line 65, in <module>
  File "mail_functions.py", line 14, in send_image
  File "my_umail.py", line 154, in __init__
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
  File "ussl.py", line 36, in wrap_socket
RuntimeError: maximum recursion depth exceeded

Is there a proper way to add ussl to firmware that does not have it in?

Thanks heaps,
davef

HTML content

Hi
Very nice code!

But is it possible to send html content? How to do that?

Tommy

OSError [Errno 104] ECONNRESET

So, I used this sample code to test out the email functionality, but no matter what I do, or even if I used your example codes, I still could not connect myself to gmail.

My Code:

`

import umail
import network

ssid = 'wifiname'
password = 'wifipass'

sender_email = 'insert email here'
sender_name = 'stuff' #sender name
sender_app_password = 'insert app pass here'
recipient_email ='receiving email here'
email_subject ='Test Email'

def connect_wifi(ssid, password):
station = network.WLAN(network.STA_IF)
station.active(True)
station.connect(ssid, password)
while station.isconnected() == False:
pass
print('Connection successful')
print(station.ifconfig())

connect_wifi(ssid, password)

smtp = umail.SMTP('smtp.gmail.com', 587) # Gmail's SSL port
smtp.login(sender_email, sender_app_password)
smtp.to(recipient_email)
smtp.write("From:" + sender_name + "<"+ sender_email+">\n")
smtp.write("Subject:" + email_subject + "\n")
smtp.write("Hello from ESP32")
smtp.send()
smtp.quit()

`

And here's the result:
image

Why in the world won't google accept my responses?

IGNORE - Issue Opened in Error

IGNORE THIS - MY FAULT.
I'd somehow not copied the last 3 lines of umail.py code

All the examples have a last line
smtp.quit()
but there is no such function/attribute in umail, so it causes an error.
It appears to work OK without this closeout.

Wemos D1 mini pro (ESP8266 based) bare minimal approach failing at 2nd statement

Hello,
Below is the output of my session to my Wemos D1 mini pro which fails at step 2.
I installed Micropython on it using instructions of https://www.jarutex.com/index.php/2020/09/20/119/ and can run Micropython programs. Already built a small web server but can not get umail working. So I flashed the Wemos again and started with a clean install of umail.py only to test the bare minimal approach. So nothing else but the standard boot.py and umail.py on the Wemos.
I changed my username and my password in right values but it does not get very far.

import umail
smtp = umail.SMTP('smtp.gmail.com', 587, username='[email protected]', password='*************')
Traceback (most recent call last):
File "", line 1, in
File "umail.py", line 30, in init
OSError: -2

I use umail.py of 29 december 2021 07:52 AM GMT+1 and MicroPython v1.13 of 2020-09-11;

Flashing again and re-downloading umail.py does not help.

Error sending the message

Hello. An error occurs when sending a message. At the same time, it is connected to the access point.
`
import network
import umail

wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect('ZB555KL', 'my_password')
wlan.ifconfig()

def email_send():
smtp = umail.SMTP('smtp.yandex.ru', 465, ssl=True)
smtp.login('[email protected]', 'my_password')
smtp.to(['[email protected]', '[email protected]'])
smtp.write("From: Aleksey [email protected]\n")
smtp.write("To: Aleksey [email protected]\n")
smtp.write("Subject: Test\n\n")
smtp.write("Send mail is work\n")
smtp.write("...\n")
smtp.send()
smtp.quit()

email_send()
`

Error:
`Traceback (most recent call last):

File "", line 46, in

File "", line 31, in email_send

File "umail.py", line 45, in init

AssertionError: start tls failed 503, ['5.5.4 Bad sequence of commands. StartTls command has been already sent. 1640644772-8lZPcmDU8T-dVQmGQxk']`

Tell me, what could be the problem?

503, "5.5.1", MAIL first - error

Yesterday I started getting these errors on some of my ESP32s. I have noticed that in umail.py that CMD_MAIL is not used in the script.

The odd thing is that on a unit that was flashed weeks ago still works. I suspect that maybe something is going wrong in the erase and flash process (v1.15 image) but have run out of things to Google and try.

Appreciate any suggestions.

Setting subject: in email

Using smtp.send was coming up with a blank subject field

Perhaps obvious, but I found to add it you add Subject: followed by two return characters before the content of the email,

i.e.

smtp.send("Subject: status update \n\n" + content)

Hope that helps !

Subject

Don't seem to be able to add a Subject?

Attachment?

Is there an easy way add option to send attachment (image)?

UTF-8 support

First of all, thanks for this library.

Unfortunately, we cannot use it in our e-mailToSMS use case, since the phone provider requires e-mails being in UTF-8 in order to allow "forwarding them to SMS" (see below). There must be something like Content-Type: text/plain; charset=utf-8 missing in the e-mail headers, because there is no content-type whatsoever.

Any proposal how to fix this easily? Thanks a lot.

Here is the e-mail returned with censored IPs and phone number:

<[[email protected]](mailto:[email protected])>: SMTPUTF8 is required, but was not offered by host
    CENSORED_IP[CENSORED_IP]
Final-Recipient: rfc822; [[email protected]](mailto:[email protected])
Original-Recipient: [rfc822;[email protected]](mailto:rfc822%[email protected])
Action: failed
Status: 5.6.7
Diagnostic-Code: X-Postfix; SMTPUTF8 is required, but was not offered by host
    CENSORED_IP[CENSORED_IP]

error in umail

Hi, using the SSL example and allowing Gmail to lower security level I had success.
thanks for supplying the code.
cheers
Gary

Hi, thanks very much for you umail.py

using example

An bare minimium example for sending a email

without SSL connection

get this error when I run the example code in REPL

exec(open('test1gmail.py').read(),globals())
Traceback (most recent call last):
File "", line 1, in
File "", line 7, in
File "umail.py", line 30, in init
IndexError: list index out of range

micropython error upycraft ide

Error when trying to send an email:

download ok
exec(open('um.py').read(),globals())
Traceback (most recent IndexError: list index out of range

Traced it to latest umail.py (downloaded today) line 30

Failure to access Gmail's SMTP server ESP32

I am trying to figure out why umail, on this platform, sometimes fails. I have attempted to log assert errors by doing this:
try: smtp = umail.SMTP('smtp.gmail.com', 465, ssl=True) except AssertionError as error: try: with open('errors.txt', 'a') as outfile: outfile.write(str(error) + '\n') except OSError: print('oops')
but have been unsuccessful. Could you tell me the correct way to log assert errors?

Thank you,
Dave

OSError: -202

Hello, while I'm trying to run any example, I'm getting the following error-

Traceback (most recent call last):
File "", line 2, in
File "umail.py", line 30, in init
OSError: -202

my code-

import umail
smtp = umail.SMTP('smtp.gmail.com', 587, username='[email protected]', password='mypassword')
smtp.to('[email protected]')
smtp.send("This is an example.")
smtp.quit()

Please ,help me to solve this. Thanks in advance

Suggest add an example where the parameters are variables

When the message parameters are variables rather than constants, it is necessary to include an explicit "\n" at the end of each line. One or more examples showing how to do this would be useful. I am successful with:

`smtp = umail.SMTP(host='smtp.gmail.com', port=465, ssl=True, username=mailFrom, password=mailPass)

def send_email(destination, subject, message):
global smtp, mailFrom
smtp.to(destination)
smtp.write("To: " + destination + "\n")
smtp.write("From: " + mailFrom + "\n")
smtp.write("Subject: " + subject + "\n")
smtp.write(message + "\n")
smtp.send()
smtp.quit()

-202 (202) wrong password at umail.SMTP()

Been trying to track down the odd error when sending a daily log.

try: smtp = umail.SMTP('smtp.gmail.com', 465, ssl=True) except Exception as error: try: with open('errors.txt', 'a') as outfile: outfile.write(str(error) + '\n') except OSError: print('oops')

What I don't understand and Google doesn't seem to have an answer is why do I see the error on this call and not the next call:
smtp.login('[email protected]', 'myPassword')
where I don't even have any logging.

Sorry can't figure out how to sort the code block.

Thanks

Problem getting uMail to work for me!

I'm a novice (dummy) when it comes to python but have been able to send emails using a standard raspberry pi. I now want to duplicate a rather simple program on a raspberry pi pico W using micropthon. I want to send an email. I have loaded uMail into the pico W and the command "import umail" seems to work just fine. I transfer the basic example from github to Thonny, change all the variables to my username, password, etc.

import umail
smtp = umail.SMTP('smtp.gmail.com', 587, username='[email protected]', password='mypassword')
smtp.to('[email protected]')
smtp.send("This is an example.")
smtp.quit()

Line 2 on Thonny has the letters SMTP in black, not red as in the github example. The word "import" on line 1 is red. This would seem to be a problem but I have no idea what it is.

When on run the code on the pico W, I get the following error:

Traceback (most recent call last):
File "", line 2, in
File "umail.py", line 30, in init
OSError: -6

Line 20 on umail.py is "addr = usocket.getaddrinfo(host, port)[0][-1]"

I am sure that I am doing something really stupid. Any ideas?

Getting message: AttributeError: 'socket' object has not attribute 'readline'

Running on uPy 1.13, specifically an openmv port running on a stm32 f765 (looks like a pyboard). Trying to connect to my normal email server (spectrum email) and am using port 587 and running the "simple" example. My guess is that the socket is not being created, but I really don't know. Here's how I have your code setup right now:
msg = sock.read(200)
print('msg: ', msg)
code = int(msg[:3])
print('code: ', code)
#sock.settimeout(DEFAULT_TIMEOUT)
sock.readline()

The print of msg shows:
msg: b'220 p-impout009.msg.pkvw.co.charter.net cmsmtp ESMTP server ready\r\n'

which seems to me that everything is OK? But if that were the case I wouldn't be getting the Attribute... message. I have tried your code on a esp32 board and it worked fine. This openmv board doesn't have internet, so I'm using a WINC1500 shield to connect to my wifi. My wifi connects fine and in fact I can run one of their examples that streams a shapshot from a camera via webserver code to my browser and it works fine - does use sockets, BTW. Both of these boards are using uPy 1.13, but obviously different ports. Do you have any ideas regarding what I can do to get around my problem?

Trying to get this work but get this handshake error - no clue what to do

I'm getting the following error and don't know how to fix:


mbedtls_ssl_handshake error: -71

Traceback (most recent call last):

File "V:\xfer-to-ubuntu\lemariva\timelapse\uMail\uMail-master\uMail-master\examples\example_basic.py", line 18, in

File "/lib/umail.py", line 46, in init

OSError: [Errno 5] EIO
******************************************** end of error output *****************************
Do you have any clues that will help me?

Error in parsing receivers address list

Hello

in the to function, the parsing is not working

instead of having

    if isinstance(addrs, str):
        addrs = [addrs]
    count = 0
    for addr in addrs_to:

we must have something like

    if isinstance(addrs, str):
        addrs_to = addrs.split()  # addrs.split(",") 
    count = 0
    for addr in addrs_to:

of course the string of receivers must have the same separator

Can't send mail using Outlook (OS Error)

I have not succeed to send mail using outlook. It works great with Gmail though.
I'm using MicroPython v1.19.1 on ESP32.
Here my code :

import umail

SMTP_PORT = 587
SMTP_HOST = "smtp.office365.com"
SMTP_USERNAME = "[email protected]"
SMTP_PASSWORD = "xxx"

WIFI_AP_SSID = "xxx-ap"
WIFI_AP_PASSWORD = "xxx"

def do_connect():
    import network
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    if not wlan.isconnected():
        print('connecting to network...')
        wlan.connect(WIFI_AP_SSID, WIFI_AP_PASSWORD)
        while not wlan.isconnected():
            pass
    print('network config:', wlan.ifconfig())


if __name__ == "__main__":
    do_connect()
    smtp = umail.SMTP(host=SMTP_HOST, port=SMTP_PORT, ssl=True, username=SMTP_USERNAME, password=SMTP_PASSWORD)
    smtp.to('[email protected]')
    smtp.send("Hello ?")
    smtp.quit()

If i'm not using SSL, there is no error, but i don't receive the mail (maybe it's a different SMTP port)

umail_error

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.