Advertisement
stuppid_bot

Спамим маил

Nov 3rd, 2013
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.94 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import sys
  3. import os
  4. import mimetypes
  5. import httplib
  6. import urllib
  7. import urllib2
  8. import re
  9. import uuid
  10. user = '***@bk.ru'
  11. pswd = '***'
  12. _ua = 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36'
  13. _cookie = ''
  14. # авторизуемся
  15. conn = httplib.HTTPConnection('m.mail.ru')
  16. conn.request('HEAD', '/cgi-bin/auth?Login=' + urllib.quote(user) + '&Password=' + urllib.quote(pswd), headers={'User-Agent': _ua})
  17. res = conn.getresponse()
  18. print res.status
  19. if res.status != 302:
  20.     print u'Сервер вернул неожиданный ответ'
  21.     sys.exit()
  22. location = res.getheader('location')
  23. if location != 'https://e.mail.ru/messages/inbox/?back=1':
  24.     print u'Ошибка авторизации'
  25.     sys.exit()
  26. _ = re.findall(r'(?:^|(?<=, ))\w+=[^;]+', res.getheader('set-cookie'))
  27. _cookie = '; '.join(_)
  28.  
  29. def fetch_path(uri, content=None, add_headers={}):
  30.     headers = {
  31.         'User-Agent': _ua,
  32.         'Cookie': _cookie
  33.     }
  34.     headers.update(add_headers)
  35.     # print headers
  36.     req = urllib2.Request('https://m.mail.ru/' + uri, content, headers)
  37.     return urllib2.urlopen(req)
  38.  
  39. class MultipartBody:
  40.     def __init__(self, boundary):
  41.         self.boundary = boundary
  42.         self.out = ''
  43.  
  44.     def add_text(self, name, text):
  45.         self.out += '--%s\r\n' % self.boundary
  46.         self.out += 'Content-Disposition: form-data; name="%s"\r\n\r\n' % name
  47.         self.out += text + '\r\n'
  48.  
  49.     def add_file(self, name, filename):
  50.         content = open(filename, 'rb').read()
  51.         self.out += '--%s\r\n' % self.boundary
  52.         self.out += 'Content-Disposition: form-data; name="%s"; filename="%s"\r\n' % (name, os.path.basename(filename))
  53.         extension = os.path.splitext(filename)[1]
  54.         self.out += 'Content-Type: %s\r\n\r\n' % (mimetypes.types_map[extension] if extension in mimetypes.types_map else 'application/octet-stream')
  55.         self.out += content + '\r\n'
  56.  
  57.     def __str__(self):
  58.         return self.out + '--' + self.boundary + '--'
  59.  
  60. resp = fetch_path('/compose/')
  61. # извелекаем значения скрытых полей
  62. hiddens = re.findall('<input type="hidden" name="([^"]+)" value="([^"]*)" />', resp.read())
  63. body = MultipartBody(uuid.uuid4().hex)
  64. for name, value in hiddens:
  65.     body.add_text(name, value)
  66. body.add_text('To', 'tz4678@gmail.com')
  67. subject = u'Привет'
  68. text = u'Иди нахуй'
  69. body.add_text('Subject', subject.encode('utf-8'))
  70. body.add_text('Body', text.encode('utf-8'))
  71. body.add_file('File', 'mime.types')
  72. body.add_text('send', '')
  73. resp = fetch_path('/compose/', str(body), {'Content-Type': 'multipart/form-data; boundary=' + body.boundary})
  74. if resp.code == 200:
  75.     content = resp.read().decode('utf-8')
  76.     # print content
  77.     if content.find(u'Письмо отправлено — Почта Mail.Ru</title>') > 0:
  78.         print u'Письмо отправлено'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement