GỬI MAIL CHO ĐIỆN THOẠI BẰNG RASPBERRY PI NGÔN NGỮ LẬP TRÌNH PYTHON GỬI MAIL CHO ĐIỆN THOẠI BẰNG RASPBERRY PI NGÔN NGỮ LẬP TRÌNH PYTHON GỬI MAIL CHO ĐIỆN THOẠI BẰNG RASPBERRY PI NGÔN NGỮ LẬP TRÌNH PYTHON
Trang 1CODE RASPBERRY PI (GUI MAIL)
import smbus
import pygame
import smtplib
bus = smbus.SMBus(1)
pygame.mixer.init()
pygame.mixer.music.load("Neverenough.wav")
#this is the address in the arduino program address = 0x04
def readMic():
volume = bus.read_byte(address)
#number = bus.write_byte_data(address,1) return volume
while True:
vol = readMic()
if vol == 1:
vol = 0
if not pygame.mixer.music.get_busy(): pygame.mixer.music.play()
sendmail()
##############################
# start talking to the SMTP server for Gmail
Trang 2Def sendmail():
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.ehlo()
# now login as my gmail user
username='bbsisterK17@gmail.com'
password='babycryK17'
s.login(username,password)
# the email objects
replyto='bbsisterK17@gmail.com' # where a reply to will go
sendto=['nguyennguyen2919@gmail.com','phuonguyenabatcha@gmail.com'] # list to send to sendtoShow='me@mẹcom' # what shows on the email as send to
subject='HELLO PARENTS' # subject line
content="BABY IS CRYING! BABY IS CRYING!" # content
# compose the email probably should use the email python module
mailtext='From: '+replytớ\nTo: '+sendtoShow+'\n'
mailtext=mailtext+'Subject:'+subject+'\n'+content
# send the email
s.sendmail(replyto, sendto, mailtext)
# we’re done
rslt=s.quit()
# print the result
print('Send successful')