Ejemplo n.º 1
0
 def send_email(self, user, receiver, public_text, email, message):
     try:
         if (Config.get("smtp", "port") == "0"):
             smtp = SMTP("localhost")
         else:
             smtp = SMTP(Config.get("smtp", "host"), Config.get("smtp", "port"))
         
         if not ((Config.get("smtp", "host") == "localhost") or (Config.get("smtp", "host") == "127.0.0.1")): 
             try:
                 smtp.starttls()
             except SMTPException as e:
                 raise SMSError("unable to shift connection into TLS: %s" % (str(e),))
             
             try:
                 smtp.login(Config.get("smtp", "user"), Config.get("smtp", "pass"))
             except SMTPException as e:
                 raise SMSError("unable to authenticate: %s" % (str(e),))
         
         try:
              smtp.sendmail(Config.get("smtp", "frommail"), email, 
                           "To:%s\nFrom:%s\nSubject:%s\n\n%s\n" % (email,
                                                                 Config.get("smtp", "frommail"),
                                                                 Config.get("Alliance", "name"),
                                                                 message,))
         except SMTPSenderRefused as e:
             raise SMSError("sender refused: %s" % (str(e),))
         except SMTPRecipientsRefused as e:
             raise SMSError("unable to send: %s" % (str(e),))
         
         smtp.quit()
         self.log_message(user, receiver, email, public_text, "email")
         
     except (socket.error, SSLError, SMTPException, SMSError) as e:
         return "Error sending message: %s" % (str(e),)
Ejemplo n.º 2
0
    def execute(self, message, user, params):

        username = Config.get("clickatell", "user")
        password = Config.get("clickatell", "pass")
        api_id = Config.get("clickatell", "api")

        get = urlencode({
            "user": Config.get("clickatell", "user"),
            "password": Config.get("clickatell", "pass"),
            "api_id": Config.get("clickatell", "api"),
        })

        try:
            status, msg = urlopen("https://api.clickatell.com/http/getbalance",
                                  get).read().split(":")

            if status in ("Credit", ):
                balance = float(msg.strip())
                if not balance:
                    message.reply(
                        "Help me help you. I need the kwan. SHOW ME THE MONEY")
                else:
                    message.reply("Current kwan balance: %d" % (balance, ))
            elif status in ("ERR", ):
                raise SMSError(msg.strip())
            else:
                message.reply(
                    "That wasn't supposed to happen. I don't really know what wrong. Maybe your mother dropped you."
                )

        except (URLError, SSLError, SMSError) as e:
            message.reply("Error sending message: %s" % (str(e), ))
Ejemplo n.º 3
0
Archivo: sms.py Proyecto: berten/merlin
    def send_clickatell(self, user, receiver, public_text, phone, message):
        try:
            # HTTP POST
            post = urlencode({
                "user": Config.get("clickatell", "user"),
                "password": Config.get("clickatell", "pass"),
                "api_id": Config.get("clickatell", "api"),
                "to": phone,
                "text": message,
            })
            # Send the SMS
            status, msg = urlopen("https://api.clickatell.com/http/sendmsg",
                                  post, 5).read().split(":")

            # Check returned status for error messages
            if status in (
                    "OK",
                    "ID",
            ):
                self.log_message(user, receiver, phone, public_text,
                                 "clickatell")
                return None
            elif status in ("ERR", ):
                raise SMSError(msg.strip())
            else:
                return ""

        except (URLError, SSLError, SMSError) as e:
            return "Error sending message: %s" % (str(e), )
Ejemplo n.º 4
0
Archivo: sms.py Proyecto: berten/merlin
    def send_googlevoice(self, user, receiver, public_text, phone, message):
        try:
            # HTTP POST
            post = urlencode({
                "accountType": "GOOGLE",
                "Email": Config.get("googlevoice", "user"),
                "Passwd": Config.get("googlevoice", "pass"),
                "service": "grandcentral",
                "source": "Merlin",
            })
            # Authenticate with Google
            text = urlopen("https://www.google.com/accounts/ClientLogin", post,
                           5).read()
            m = re.search(r"^Auth=(.+?)$", text, re.M)
            if m is None:
                raise SMSError("unable to authenticate")
            auth = m.group(1)

            # HTTP POST
            post = urlencode({
                "id": '',
                "phoneNumber": phone,
                "text": message,
                "auth": auth,
                "_rnr_se": Config.get("googlevoice", "api"),
            })
            # Send the SMS
            req = Request("https://www.google.com/voice/sms/send/")
            req.add_header('Authorization', "GoogleLogin auth=" + auth)
            text = urlopen(req, post, 5).read()
            if text != '{"ok":true,"data":{"code":0}}':
                raise SMSError("success code not returned")

            # Allow a small amount of time for the request to be processed
            time.sleep(5)

            # HTTP GET
            get = urlencode({
                "auth": auth,
            })
            # Request the SMS inbox feed
            req = Request("https://www.google.com/voice/inbox/recent/sms/?" +
                          get)
            req.add_header('Authorization', "GoogleLogin auth=" + auth)
            text = urlopen(req, None, 5).read()

            # Parse the feed and extract JSON data
            m = re.search(self.googlevoice_regex_json(), text)
            if m is None:
                raise SMSError("json data not found in feed")
            data = json.loads(m.group(1))
            for conversation in data['messages'].values():
                # One of the conversations should match
                #  the phone number we just tried SMSing
                if conversation['phoneNumber'] == phone:
                    id = conversation['id']
                    read = conversation['isRead']

                    # Parse the feed and extract the relevant conversation
                    m = re.search(
                        self.googlevoice_regex_conversation(id, read), text,
                        re.S)
                    if m is None:
                        raise SMSError("conversation not found in SMS history")

                    # Parse the conversation and extract the message
                    m = re.search(self.googlevoice_regex_message(message),
                                  m.group(1))
                    if m is None:
                        #raise SMSError("message not found in conversation")
                        continue

                    # Check the message for error replies
                    if m.group(4) is None:
                        self.log_message(user, receiver, phone, public_text,
                                         "googlevoice")
                        return None
                    else:
                        return m.group(4)

            else:
                raise SMSError(
                    "message not found in any of the matching conversations")

        except (URLError, SSLError, SMSError) as e:
            return "Error sending message: %s" % (str(e), )