Page 3 of 4

Re: uMail - A lightweight SMTP client for MicroPython

Posted: Sat Feb 08, 2020 7:28 pm
by mikronauts
The issue appears to have been with MicroPython.

After flashing the latest build from

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

umail worked again :)

Re: uMail - A lightweight SMTP client for MicroPython

Posted: Wed Jul 22, 2020 9:35 pm
by ScotsDon
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??

Re: uMail - A lightweight SMTP client for MicroPython

Posted: Thu Jul 23, 2020 3:18 pm
by ScotsDon
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.

Re: uMail - A lightweight SMTP client for MicroPython

Posted: Tue Jul 28, 2020 4:37 pm
by tom1
how to send via umail, attachments?

Re: uMail - A lightweight SMTP client for MicroPython

Posted: Fri Aug 07, 2020 2:30 am
by davef
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

Re: uMail - A lightweight SMTP client for MicroPython

Posted: Mon Aug 10, 2020 7:39 pm
by davef
Subject line.

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

Thanks,
Dave

Re: uMail - A lightweight SMTP client for MicroPython

Posted: Tue Aug 18, 2020 5:40 pm
by SpotlightKid
@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.

Re: uMail - A lightweight SMTP client for MicroPython

Posted: Tue Aug 18, 2020 8:09 pm
by davef
@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

Re: uMail - A lightweight SMTP client for MicroPython

Posted: Tue Aug 18, 2020 11:02 pm
by davef
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

Re: uMail - A lightweight SMTP client for MicroPython

Posted: Fri Sep 11, 2020 12:22 am
by davef
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)