Sending email

Questions and discussion about The WiPy 1.0 board and CC3200 boards.
Target audience: Users with a WiPy 1.0 or CC3200 board.
Ferretproof
Posts: 8
Joined: Sun Oct 11, 2015 4:56 pm

Re: Sending email

Post by Ferretproof » Fri Oct 23, 2015 12:06 pm

Thanks Daniel.
With your smtplib and the 2nd example I was able to send mail to Pushover and receive a notification on my phone. How cool is that?!


Cheers,

Ray

User avatar
danicampora
Posts: 342
Joined: Tue Sep 30, 2014 7:20 am
Contact:

Re: Sending email

Post by danicampora » Fri Oct 23, 2015 12:09 pm

Hello Ray!

That's awesome, thanks for the update. I'll clean up the file a bit, implement Damien's suggestion and then add it to the official library.

Cheers,
Daniel

User avatar
platforma
Posts: 258
Joined: Thu May 28, 2015 5:08 pm
Location: Japan

Re: Sending email

Post by platforma » Sat Oct 24, 2015 9:27 pm

That's great. Since I read your post Ray, I got pushover and registered. Going to wait for the smtplib to join the official library and going to give it a try! Care to share your example? :)

alanb
Posts: 6
Joined: Sat Oct 17, 2015 3:39 pm

Re: Sending email

Post by alanb » Sat Oct 24, 2015 10:35 pm

I tested sending through Yahoo's smtp server and it worked like a charm.

Code: Select all

>>> 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()

ghoff
Posts: 1
Joined: Sat Nov 14, 2015 12:39 am

Re: Sending email

Post by ghoff » Sat Nov 14, 2015 12:41 am

I loaded the library and modified the program with my mail credentials and it worked the first time. I sent a message from my gmail account to my work account. I have since created an e-mail account for the WiPy to use.

mbevilacqua
Posts: 6
Joined: Sat May 07, 2016 10:30 pm

Re: Sending email

Post by mbevilacqua » Sun May 08, 2016 6:04 pm

Has there been any progress on getting urllib on the WiPy?

ideal2545
Posts: 12
Joined: Tue May 17, 2016 9:08 am

Re: Sending email

Post by ideal2545 » Wed May 25, 2016 6:56 am

any more progress on this by chance, i've been trying your lib on an esp8266 but when i do an import i run straight out of memory :(

MCHobby
Posts: 52
Joined: Mon Jan 26, 2015 2:05 pm
Contact:

Re: Sending email

Post by MCHobby » Sat Jun 18, 2016 3:17 pm

I was looking for smtplib but did not locate it.
Does someone have any information about it OR is this retired?

Regards,
Dominique

SASM
Posts: 6
Joined: Thu Feb 08, 2018 11:28 pm

Re: Sending email

Post by SASM » Sun May 27, 2018 3:59 am

[quote=danicampora post_id=6120 time=1445525817 user_id=338]
Hi!

I have a first version of the smtplib.py file, it's compact and doesn't need any external libraries. Attached here. Please test and let us know your results, with your help we can make it good enough to make it part of the official library. Examples:

[b]Following scripts assume an already established internet connection[/b]

[b]Without TLS/SSL:[/b]

[code]
to = 'recipient@mail.com'
gmail_user = 'some.user@wipy.io'
gmail_pwd = 'password'
smtpserver = smtplib.SMTP("smtp02.hostnet.nl", 587, tls=False)
smtpserver.helo()
smtpserver.login(gmail_user, gmail_pwd)
header = 'To:' + to + '\n' + 'From: ' + gmail_user + '\n' + 'Subject: Email from the WiPy \n'
msg = header + '\n Hi, \n this is The WiPy emailing ;-) \n\n Cheers, \n The WiPy'
smtpserver.sendmail(gmail_user, to, msg)
smtpserver.close()
[/code]

[b]With TLS/SSL:[/b]

[code]
to = 'recipient@mail.com'
gmail_user = 'some.user@gmail.com'
gmail_pwd = 'password'
smtpserver = smtplib.SMTP("smtp.gmail.com", 465)
smtpserver.helo()
smtpserver.login(gmail_user, gmail_pwd)
header = 'To:' + to + '\n' + 'From: ' + gmail_user + '\n' + 'Subject: Email from the WiPy \n'
msg = header + '\n Hi, \n this is The WiPy emailing ;-) \n\n Cheers, \n The WiPy'
smtpserver.sendmail(gmail_user, to, msg)
smtpserver.close()
[/code]

The WiPy doesn't support turning a standard socket into a secure one on the fly, it needs to be secure from the very beginning, therefore there's no need to call [code]smtpserver.starttls()[/code], but on the other hand, when creating the stmp instance with [b]tls=True[/b] (default value), the correct secure port must be used (465 in the case of gmail).

[b]Remark about gmail:[/b] Since sometime ago gmail (and also other popular mail servers) require OAuth2 to authenticate unless you allow "non secure apps" to access your account. OAuth2 is out of the scope of smtplib and I really don't know how to deal with it yet. Details can be found here: https://support.google.com/accounts/ans ... 0255?hl=en


Cheers,
Daniel
[/quote]

I am trying to send emails through an ESP32 with micropython with the same code you provide, however I get the following error, can someone help me? I am using the library provided here as well.

Traceback (most recent call last):
File "<stdin>", line 19, in <module>
File "smtplib.py", line 84, in __init__
File "smtplib.py", line 110, in connect
AttributeError: 'module' object has no attribute 'IPPROTO_SEC'

fariz
Posts: 5
Joined: Mon Jun 18, 2018 4:38 pm
Location: Santo Domingo
Contact:

Re: Sending email

Post by fariz » Mon Jun 25, 2018 5:52 pm

Hi, I had lots of trouble trying to send emails from esp8266 that way, I worked the issue around using available services on the cloud as Thinkspeak and Pythonanywhere for sending emails, (Treated IFTT but is unstable with gmail), Configure a channel in Thingspeak, a Thinghttp instance, React and Timecontrol (there are plenty of tutorials on this on youtube and forums), then prepared a web app in pythonanywhere to proccess the emails in python (Django framework) . It works very well and the only thing you have to program in the esp8266 is the comunication protocol, and send the data in mqtt to Thingspeak. Please let me know if you are interested in details.

Post Reply