Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import sys
- import os
- import mimetypes
- import httplib
- import urllib
- import urllib2
- import re
- import uuid
- user = '***@bk.ru'
- pswd = '***'
- _ua = 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36'
- _cookie = ''
- # авторизуемся
- conn = httplib.HTTPConnection('m.mail.ru')
- conn.request('HEAD', '/cgi-bin/auth?Login=' + urllib.quote(user) + '&Password=' + urllib.quote(pswd), headers={'User-Agent': _ua})
- res = conn.getresponse()
- print res.status
- if res.status != 302:
- print u'Сервер вернул неожиданный ответ'
- sys.exit()
- location = res.getheader('location')
- if location != 'https://e.mail.ru/messages/inbox/?back=1':
- print u'Ошибка авторизации'
- sys.exit()
- _ = re.findall(r'(?:^|(?<=, ))\w+=[^;]+', res.getheader('set-cookie'))
- _cookie = '; '.join(_)
- def fetch_path(uri, content=None, add_headers={}):
- headers = {
- 'User-Agent': _ua,
- 'Cookie': _cookie
- }
- headers.update(add_headers)
- # print headers
- req = urllib2.Request('https://m.mail.ru/' + uri, content, headers)
- return urllib2.urlopen(req)
- class MultipartBody:
- def __init__(self, boundary):
- self.boundary = boundary
- self.out = ''
- def add_text(self, name, text):
- self.out += '--%s\r\n' % self.boundary
- self.out += 'Content-Disposition: form-data; name="%s"\r\n\r\n' % name
- self.out += text + '\r\n'
- def add_file(self, name, filename):
- content = open(filename, 'rb').read()
- self.out += '--%s\r\n' % self.boundary
- self.out += 'Content-Disposition: form-data; name="%s"; filename="%s"\r\n' % (name, os.path.basename(filename))
- extension = os.path.splitext(filename)[1]
- self.out += 'Content-Type: %s\r\n\r\n' % (mimetypes.types_map[extension] if extension in mimetypes.types_map else 'application/octet-stream')
- self.out += content + '\r\n'
- def __str__(self):
- return self.out + '--' + self.boundary + '--'
- resp = fetch_path('/compose/')
- # извелекаем значения скрытых полей
- hiddens = re.findall('<input type="hidden" name="([^"]+)" value="([^"]*)" />', resp.read())
- body = MultipartBody(uuid.uuid4().hex)
- for name, value in hiddens:
- body.add_text(name, value)
- body.add_text('To', 'tz4678@gmail.com')
- subject = u'Привет'
- text = u'Иди нахуй'
- body.add_text('Subject', subject.encode('utf-8'))
- body.add_text('Body', text.encode('utf-8'))
- body.add_file('File', 'mime.types')
- body.add_text('send', '')
- resp = fetch_path('/compose/', str(body), {'Content-Type': 'multipart/form-data; boundary=' + body.boundary})
- if resp.code == 200:
- content = resp.read().decode('utf-8')
- # print content
- if content.find(u'Письмо отправлено — Почта Mail.Ru</title>') > 0:
- print u'Письмо отправлено'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement