[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'