Page 3 of 4

Re: Sending email

Posted: Fri Oct 23, 2015 12:06 pm
by Ferretproof
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

Re: Sending email

Posted: Fri Oct 23, 2015 12:09 pm
by danicampora
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

Re: Sending email

Posted: Sat Oct 24, 2015 9:27 pm
by platforma
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? :)

Re: Sending email

Posted: Sat Oct 24, 2015 10:35 pm
by alanb
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()

Re: Sending email

Posted: Sat Nov 14, 2015 12:41 am
by ghoff
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.

Re: Sending email

Posted: Sun May 08, 2016 6:04 pm
by mbevilacqua
Has there been any progress on getting urllib on the WiPy?

Re: Sending email

Posted: Wed May 25, 2016 6:56 am
by ideal2545
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 :(

Re: Sending email

Posted: Sat Jun 18, 2016 3:17 pm
by MCHobby
I was looking for smtplib but did not locate it.
Does someone have any information about it OR is this retired?

Regards,
Dominique

Re: Sending email

Posted: Sun May 27, 2018 3:59 am
by SASM
[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'

Re: Sending email

Posted: Mon Jun 25, 2018 5:52 pm
by fariz
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.