Code: Select all
from machine import Pin
import smtplib
p4 = Pin(4, Pin.IN)
p0 = Pin(0, Pin.OUT)
p0.off()
def email_send():
fromaddr = '...@yandex.ru'
toaddrs = '...@yandex.ru'
msg = ("From: %s\r\nTo: %s\r\n\r\n"
% (fromaddr, ", ".join(toaddrs))) + 'alarm'
server = smtplib.SMTP_SSL('smtp.yandex.ru')
server.login('...', '...')
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
while True:
if p4.value() == 0:
p0.value(1)
email_send()
elif p4.value() == 1:
p0.value(0)
After running the script and clicking the button, it returns the error "Traceback (most recent call last):
Code: Select all
File" <stdin>", line 51, in <module>
File "<stdin>", line 39, in email_send
AttributeError: 'module' object has no attribute 'SMTP_SSL'"