def send_img(file_name): fromaddr = "email" toaddr = "email" msg = MIMEMultipart() msg['From'] = fromaddr msg['To'] = toaddr msg['Subject'] = "Motion at " + file_name body = "Motion was detected" msg.attach(MIMEText(body, 'plain')) filename = file_name + '.jpeg' #used to print the file name *debuging * #print("Updated to: " +filename) attachment = open("/home/pi/Hackathon_Video/" + filename, "rb") part = MIMEBase('application', 'octet-stream') part.set_payload((attachment).read()) encoders.encode_base64(part) part.add_header('Content-Disposition', "attachment; filename= %s" % filename) msg.attach(part) server = smtplib.SMTP('smtp.gmail.com', 587) server.starttls() server.login(fromaddr, "password") text = msg.as_string() server.sendmail(fromaddr, toaddr, text) server.quit() os.remove("/home/pi/Hackathon_Video/" + file_name + '.jpeg')
def sendMail(data): mail.attach(MIMEText(body, 'plain')) print(data) dat = '%s.jpg' % data print(dat) attachment = open(cam / dat, 'rb') image = MIMEImage(attachment.read()) attachment.close() mail.attach(image) server = smtplib.SMTP('smtp.gmail.com', 587) server.starttls() server.login(fromaddr, "YourPassword" ) # Change this.. Will login to your email to send an email.. text = mail.as_string() server.sendmail(fromaddr, toaddr, text) print("Image Sent..!!!") server.quit()
def send_mail(): server = smtplib.SMTP( 'smtp.gmail.com', 587) #what is 587 this is a protical for mail transmission server.ehlo() #ehlo? identifies smtp server server.starttls( ) #? it is one way to create an insecure connection and then updating the transport layer security server.ehlo() server.login('*****@*****.**', 'hprthjumcydnjvwf') subject = 'Price fell down!' body = 'Check the amazon link https://www.amazon.co.uk/dp/B0875K11W6/ref=uk_a_phonex_2' msg = f"Subject: {subject}\n\n{body} " # what does this mean this is the product and how the page is set out # what is that f for? server.sendmail('*****@*****.**', '*****@*****.**', msg) print('HEY EMAIL HAS BEEN SENT!') server.quit()
import http.client conn = http.client.HTTPSConnection("www.python.org") conn.request("GET", "/") resp = conn.getresponse() resp.code resp.length ### SMTP # https://docs.python.org/3/library/smtplib.html import smtplib msg = "From: e@mail\r\nTo: e@mail\r\n\r\nText" server = smtplib.SMTP('localhost') server.sendmail("from@addr", "to@addr", msg) server.quit() ### Модуль email ### POP3 # https://docs.python.org/3/library/poplib.html # https://docs.python.org/3/library/getpass.html import getpass, poplib M = poplib.POP3('localhost') M.user(getpass.getuser()) M.pass_(getpass.getpass()) numMessages = len(M.list()[1]) for i in range(numMessages): for j in M.retr(i + 1)[1]: print j
import http.client conn = http.client.HTTPSConnection("www.python.org") conn.request("GET", "/") resp = conn.getresponse() resp.code resp.length # SMTP # https://docs.python.org/3/library/smtplib.html import smtplib msg = "From: e@mail\r\nTo: e@mail\r\n\r\nText" server = smtplib.SMTP('localhost') server.sendmail("from@addr", "to@addr", msg) server.quit() # module email # POP3 # https://docs.python.org/3/library/poplib.html # https://docs.python.org/3/library/getpass.html import getpass, poplib M = poplib.POP3('localhost') M.user(getpass.getuser()) M.pass_(getpass.getpass()) numMessages = len(M.list()[1]) for i in range(numMessages): for j in M.retr(i+1)[1]: print j