Page 1 of 4

Sending email

Posted: Wed Oct 21, 2015 2:47 pm
by Ferretproof
Hi,

I was playing with the app/site Pushover https://pushover.net/ which is pretty cool. It allowes you to receive notifications on your pc, smartphone and/or tablet.
Was thinking... would be cool to be able to use this when some event happens on the WiPy. (for example: some senson triggers a pin which triggers the Wipy to send an email (or rest call over HTTPS) to the Pushover API.

But here I am stuck. I tried the example from this page: https://www.kickstarter.com/projects/wi ... escription)
Image

when I do this:

Code: Select all

import smtplib
sender = 'my_email_address'
receivers = ['your_email_address']
message = """From: me <my_email_address>
To: You <your_email_address>
Subject: Trouble at mill.

One on't cross beams gone owt askew on treddle. 
"""

server = smtplib.SMTP('smtp.gmail.com:587')
This last line fails:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: no such attribute
Before I did this, i tried to find the library smtplib.py somewhere.
I only found a dummy library here: https://github.com/micropython/micropython-lib
I understand it is basically an empty file called smtplib.py which I saved to '/flash/lib/smtplib.py'

Pretty sure I am doing something very wrong here, but what?

Re: Sending email

Posted: Wed Oct 21, 2015 3:25 pm
by platforma
Hey Ferretproof!

That's a neat idea, i never heard of pushover, gotta have a look into it!
I think the problem is that the smtplib module is not implemented, I installed smtplib via upip for unix port and got the same results as you. But looking at micropython-lib/smtplib I can only see a dummy package.

Re: Sending email

Posted: Wed Oct 21, 2015 4:02 pm
by dhylands
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.

Re: Sending email

Posted: Wed Oct 21, 2015 4:10 pm
by mbirth
dhylands wrote: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.
As long as the server doesn't insist on some better auth scheme which would need a TLS/SSL library. But you're right, the basic order is like:

Code: Select all

HELO my.hostname.com
MAIL FROM: "Sender name" <sender@ddress.com>
RCPT TO: "Recipient name" <rcpt@ddress.com>
DATA
From: "Appears only in your mail client" <whatever@anonymous.com>
To: "Appears only in your mail client" <whoever@somewhere.com>
Subject: Lets see if this works (don't use special characters like umlauts, etc. here)

Mail text
.
QUIT
The empty line between mail headers and Mail text is required.

A single dot marks the end of the mail and sends it. The QUIT after that is just courtesy. ;)

Re: Sending email

Posted: Wed Oct 21, 2015 5:40 pm
by Ferretproof
Thanks for the replies. I am going to try that.
Not sure it works as I mainly use google which I think require TLS, but what fun trying anyway :D

...but one would think the smtplib sould work given the example of the kickstarter website...

Re: Sending email

Posted: Wed Oct 21, 2015 9:25 pm
by danicampora
Hi,

smtplib does work because that's what I used for the KS videos... but it needs a bit of tweaking. I will clean it up and make it public soon.

Cheers,
Daniel

Re: Sending email

Posted: Wed Oct 21, 2015 9:58 pm
by Ferretproof
Great, that is good news. I (we?) will wait for that.

Re: Sending email

Posted: Thu Oct 22, 2015 8:06 am
by lucien2k
urllib is another library that would be useful, I was planning to use a rest api to push data from the wipy to a central system.

I had a brief play with it because I figure it is 99% sockets and it is pure python, but if you already have something working that would be great.

Re: Sending email

Posted: Thu Oct 22, 2015 8:08 am
by danicampora
I agree, urllib will be great as well.

Re: Sending email

Posted: Thu Oct 22, 2015 8:38 am
by Ferretproof
That would be award winning, especially when it also supports HTTPS.
(tell me when I ask too much :D)