uMail - A lightweight SMTP client for MicroPython

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
mikronauts
Posts: 13
Joined: Thu Nov 03, 2016 10:12 pm

Re: uMail - A lightweight SMTP client for MicroPython

Post by mikronauts » Sat Feb 08, 2020 7:28 pm

The issue appears to have been with MicroPython.

After flashing the latest build from

http://micropython.org/resources/firmwa ... 0abcf2.bin

umail worked again :)

ScotsDon
Posts: 4
Joined: Wed Jul 22, 2020 9:18 pm

Re: uMail - A lightweight SMTP client for MicroPython

Post by ScotsDon » Wed Jul 22, 2020 9:35 pm

I have fallen at the first fence. How do you set up the "import umail" on an ESP32 development board?

I am using uPyCraft from a Windows 10 PC to talk to the ESP32. I have flashed micropython to the board and run a simple micropython program to flash an LED on the board, so that works. I have downloaded the umail zip file to the PC from Github and extracted the files, which mainly consists of the umail.py python script.

But what do I do now??

ScotsDon
Posts: 4
Joined: Wed Jul 22, 2020 9:18 pm

Re: uMail - A lightweight SMTP client for MicroPython

Post by ScotsDon » Thu Jul 23, 2020 3:18 pm

OK I've got this fully working now, so ignore the previous post. For the benefit of any other novices, this is what you do:

1 From Github (address provided in this topic above), go to CODE and download the zip file. This contains the software.
2 Unzip it and place the contents in the "workspace" folder on your PC (I am assuming you are using uPyCraft IDE, which is very good).
3 In uPyCraft, open (File/Open) the umail.py file and Download it (Tools/Download). This installs it into the device folder.
4 In a python script, try "import umail". This should work.
5 Carry on with the other tutorials, which explain how to send an email. For me, this worked first time.

I must congratulate the author on a very handy little module. I will use it to notify myself via email of any changes to the parameters I will be monitoring. I may also set up a web server to monitor directly should I need to.

tom1
Posts: 1
Joined: Tue Jul 28, 2020 4:36 pm

Re: uMail - A lightweight SMTP client for MicroPython

Post by tom1 » Tue Jul 28, 2020 4:37 pm

how to send via umail, attachments?

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

Re: uMail - A lightweight SMTP client for MicroPython

Post by davef » Fri Aug 07, 2020 2:30 am

tom1,

Find anything? I finally got uMail to work on the ESP32 and now I also want to send attachments. I use sendmail in a Python script on a RaspberryPi. Had a pretty good look around and all the tutorials I see use sendmail.

Dave

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

Re: uMail - A lightweight SMTP client for MicroPython

Post by davef » Mon Aug 10, 2020 7:39 pm

Subject line.

Has anyone incorporated a subject line in uMail and that they are willing to share?

Thanks,
Dave

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

Re: uMail - A lightweight SMTP client for MicroPython

Post by SpotlightKid » Tue Aug 18, 2020 5:40 pm

@davef: uMail does not format the email for you. It is equivalent to the "smtplib" module in the CPython standard library. If you want a subject or any other header, you need to format an RFC5322-compliant message string. On CPython your would do this with the "email" module, but that is much too big to be ported to MicroPython.

You can read about the basics of the internet message format on Wikipedia: https://en.wikipedia.org/wiki/Email#Int ... age_Format

If you want attachments, you need to format an RFC2045-compliant multipart message string.

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

Re: uMail - A lightweight SMTP client for MicroPython

Post by davef » Tue Aug 18, 2020 8:09 pm

@SpotlightKid,

With some help here:
viewtopic.php?f=11&p=50054#p50054
I have the subject line issue sorted.

I will now read about
RFC2045-compliant multipart message string
as attaching a .csv file will be easier than copying up to 120K of text in a text editor and giving it a .csv name.

Thanks for that.
Dave

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

Re: uMail - A lightweight SMTP client for MicroPython

Post by davef » Tue Aug 18, 2020 11:02 pm

In a working Python email application I have:

Code: Select all

#  open the file to be sent
    filename = my_file
    attachment = open(my_file, 'rb')

 #  instance of MIMEBase and named as p
    p = MIMEBase('application', 'octet-stream')

 #  To change the payload into encoded form
    p.set_payload((attachment).read())

 #  encode into base64
    encoders.encode_base64(p)

    p.add_header('Content-Disposition', 'attachment; filename= %s' % filename)

 #  attach the instance 'p' to instance 'msg'
    msg.attach(p)
Appears the first thing required is MIMEbase. Looked around and found this:
https://pypi.org/project/mime/#files

Can't see the keyword attach or attachment in the source. Also, looks like I would need:

Code: Select all

 #  instance of MIMEMultipart
    msg = MIMEMultipart()
MIMEMultipart() to be able to get <msg>. It is not clear to me if this source could do what I want.

Can anyone point to an easier method of attaching files to a Gmail SMTP message?

Thanks,
Dave

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

Re: uMail - A lightweight SMTP client for MicroPython

Post by davef » Fri Sep 11, 2020 12:22 am

Just in case you might want to do an attachment. Go to https://github.com/shawwwn/uMail/issues/2 and in the example by varna9000 change the lines:

Code: Select all

smtp.write("Content-Type: image/jpeg; name=cam.jpeg\n")
smtp.write("Content-Disposition: attachment; filename="cam.jpeg"\n")
For a specific dated .csv file I changed them to:

Code: Select all

     #  build today's filename into Content-Type and Content-Disposition
        csv_file = 'House-' + date + '.csv\n'
        content_type = 'Content-Type: text/csv; name=' + csv_file
        content_disposition = 'Content-Disposition: attachment; filename=' + csv_file 
        smtp.write(content_type)
        smtp.write(content_disposition)

Post Reply