Esempio n. 1
0
    def sendmessage(self, message, options={}):
        direct = options.get('to', 'anyone')
        if direct in ('anyone', 'connections-only'):
            url = "http://api.linkedin.com/v1/people/~/shares"
            body = {
                "comment": message,
                "content": {
                    "title": options.get('subject', ''),
                    "submitted-url": options.get('link', ''),
                    "submitted-image-url": options.get('picture', ''),
                    "description": options.get('description', ''),
                },
                "visibility": {
                    "code": direct
                }
            }
        else:
            # we have to do a direct message, different api
            url = "http://api.linkedin.com/v1/people/~/mailbox"

            profile = self.account.get('profile', {})
            from_email = from_ = profile.get('verifiedEmail')
            fullname = profile.get('displayName', None)

            to_addrs = AddressList(options['to'])
            subject = options.get('subject', config.get('share_subject', 'A web link has been shared with you'))
            title = options.get('title', options.get('link', options.get('shorturl', '')))
            description = options.get('description', '')[:280]

            to_ = []
            for a in to_addrs.addresslist:
                to_.append({'person': {'_path': '/people/'+a[1] }})

            c.safeHTML = safeHTML
            c.options = options
            
            # insert the url if it is not already in the message
            c.longurl = options.get('link')
            c.shorturl = options.get('shorturl')
            
            # get the title, or the long url or the short url or nothing
            # wrap these in literal for text email
            c.from_name = literal(fullname)
            c.subject = literal(subject)
            c.from_header = literal(from_)
            c.to_header = literal(to_)
            c.title = literal(title)
            c.description = literal(description)
            c.message = literal(message)
    
            text_message = render('/text_email.mako').encode('utf-8')
            
            body = { 
                'recipients': {'values': to_},
                'subject': subject,
                'body': text_message
            }
        return self.rawcall(url, body, method="POST")
Esempio n. 2
0
    def sendmessage(self, message, options={}):
        direct = options.get('to', 'anyone')
        if direct in ('anyone', 'connections-only'):
            url = "http://api.linkedin.com/v1/people/~/shares"
            body = {
                "comment": message,
                "content": {
                    "title": options.get('subject', ''),
                    "submitted-url": options.get('link', ''),
                    "submitted-image-url": options.get('picture', ''),
                    "description": options.get('description', ''),
                },
                "visibility": {
                    "code": direct
                }
            }
        else:
            # we have to do a direct message, different api
            url = "http://api.linkedin.com/v1/people/~/mailbox"

            profile = self.account.get('profile', {})
            from_email = from_ = profile.get('verifiedEmail')
            fullname = profile.get('displayName', None)

            to_addrs = AddressList(options['to'])
            subject = options.get(
                'subject',
                config.get('share_subject',
                           'A web link has been shared with you'))
            title = options.get(
                'title', options.get('link', options.get('shorturl', '')))
            description = options.get('description', '')[:280]

            to_ = []
            for a in to_addrs.addresslist:
                to_.append({'person': {'_path': '/people/' + a[1]}})

            c.safeHTML = safeHTML
            c.options = options

            # insert the url if it is not already in the message
            c.longurl = options.get('link')
            c.shorturl = options.get('shorturl')

            # get the title, or the long url or the short url or nothing
            # wrap these in literal for text email
            c.from_name = literal(fullname)
            c.subject = literal(subject)
            c.from_header = literal(from_)
            c.to_header = literal(to_)
            c.title = literal(title)
            c.description = literal(description)
            c.message = literal(message)

            text_message = render('/text_email.mako').encode('utf-8')

            body = {
                'recipients': {
                    'values': to_
                },
                'subject': subject,
                'body': text_message
            }
        return self.rawcall(url, body, method="POST")
Esempio n. 3
0
    def sendmessage(self, message, options={}):
        result = error = None

        profile = self.account.get("profile", {})
        from_email = from_ = profile["emails"][0]["value"]
        fullname = profile.get("displayName", None)
        if fullname:
            from_email = '"%s" <%s>' % (Header(fullname, "utf-8").encode(), Header(from_, "utf-8").encode())

        url = "https://mail.google.com/mail/b/%s/smtp/" % from_
        # 'to' parsing
        address_list = AddressList(options.get("to", ""))
        if len(address_list) == 0:
            return None, {"provider": self.host, "message": "recipient address must be specified", "status": 0}
        to_headers = []
        for addr in address_list:
            if not addr[1] or not "@" in addr[1]:
                return (
                    None,
                    {"provider": self.host, "message": "recipient address '%s' is invalid" % (addr[1],), "status": 0},
                )
            if addr[0]:
                to_ = '"%s" <%s>' % (Header(addr[0], "utf-8").encode(), Header(addr[1], "utf-8").encode())
            else:
                to_ = Header(addr[1], "utf-8").encode()
            to_headers.append(to_)
        assert to_headers  # we caught all cases where it could now be empty.

        server = SMTP(self.host, self.port)
        # in the app:main set debug = true to enable
        if asbool(config.get("debug", False)):
            server.set_debuglevel(True)

        subject = options.get("subject", config.get("share_subject", "A web link has been shared with you"))
        title = options.get("title", options.get("link", options.get("shorturl", "")))
        description = options.get("description", "")[:280]

        msg = MIMEMultipart("alternative")
        msg.set_charset("utf-8")
        msg.add_header("Subject", Header(subject, "utf-8").encode())
        msg.add_header("From", from_email)
        for to_ in to_headers:
            msg.add_header("To", to_)

        c.safeHTML = safeHTML
        c.options = options

        # insert the url if it is not already in the message
        c.longurl = options.get("link")
        c.shorturl = options.get("shorturl")

        # reset to unwrapped for html email, they will be escaped
        c.from_name = fullname
        c.subject = subject
        c.from_header = from_
        c.title = title
        c.description = description
        c.message = message

        c.thumbnail = options.get("picture_base64", "") != ""

        if c.thumbnail:
            part2 = MIMEMultipart("related")

            html = MIMEText(render("/html_email.mako").encode("utf-8"), "html")
            html.set_charset("utf-8")

            # FIXME: we decode the base64 data just so MIMEImage can re-encode it as base64
            image = MIMEImage(base64.b64decode(options.get("picture_base64")), "png")
            image.add_header("Content-Id", "<thumbnail>")
            image.add_header("Content-Disposition", "inline; filename=thumbnail.png")

            part2.attach(html)
            part2.attach(image)
        else:
            part2 = MIMEText(render("/html_email.mako").encode("utf-8"), "html")
            part2.set_charset("utf-8")

        # get the title, or the long url or the short url or nothing
        # wrap these in literal for text email
        c.from_name = literal(fullname)
        c.subject = literal(subject)
        c.from_header = literal(from_)
        c.title = literal(title)
        c.description = literal(description)
        c.message = literal(message)

        part1 = MIMEText(render("/text_email.mako").encode("utf-8"), "plain")
        part1.set_charset("utf-8")

        msg.attach(part1)
        msg.attach(part2)

        try:
            try:
                try:
                    server.starttls()
                except smtplib.SMTPException:
                    logger.info("smtp server does not support TLS")
                try:
                    server.ehlo_or_helo_if_needed()
                    server.authenticate(url, self.consumer, self.oauth_token)
                    server.sendmail(from_, to_headers, msg.as_string())
                except smtplib.SMTPRecipientsRefused, exc:
                    for to_, err in exc.recipients.items():
                        error = {"provider": self.host, "message": err[1], "status": err[0]}
                        break
                except smtplib.SMTPException, exc:
                    error = {
                        "provider": self.host,
                        "message": "%s: %s" % (exc.smtp_code, exc.smtp_error),
                        "status": exc.smtp_code,
                    }
                except UnicodeEncodeError, exc:
                    raise
Esempio n. 4
0
    def sendmessage(self, message, options={}):
        result = error = None

        profile = self.account.get('profile', {})
        from_email = from_ = profile.get('verifiedEmail')
        fullname = profile.get('displayName', None)

        address_list = AddressList(options.get('to', ''))
        if len(address_list)==0:
            return None, {
                "provider": domain,
                "message": "recipient address must be specified",
                "status": 0
            }
        to_ = []
        for addr in address_list:
            if not addr[1] or not '@' in addr[1]:
                return None, {
                    "provider": domain,
                    "message": "recipient address '%s' is invalid" % (addr[1],),
                    "status": 0
                }
            # expect normal email address formats, parse them
            to_.append({'name': addr[0], 'email': addr[1]})

        assert to_ # we caught all cases where it could now be empty.

        subject = options.get('subject', config.get('share_subject', 'A web link has been shared with you'))
        title = options.get('title', options.get('link', options.get('shorturl', '')))
        description = options.get('description', '')[:280]
        
        c.safeHTML = safeHTML
        c.options = options

        # insert the url if it is not already in the message
        c.longurl = options.get('link')
        c.shorturl = options.get('shorturl')


        # reset to unwrapped for html email, they will be escaped
        c.from_name = fullname
        c.subject = subject
        c.from_header = from_
        c.title = title
        c.description = description
        c.message = message
        c.thumbnail = False

        html_message = render('/html_email.mako').encode('utf-8')

        # get the title, or the long url or the short url or nothing
        # wrap these in literal for text email
        c.from_name = literal(fullname)
        c.subject = literal(subject)
        c.from_header = literal(from_)
        c.title = literal(title)
        c.description = literal(description)
        c.message = literal(message)

        text_message = render('/text_email.mako').encode('utf-8')

        params = [{
                "message":
                    {"subject":subject,
                     "from":{"name": fullname, "email":from_},
                     "to":to_,
                     "simplebody":{
                        "text": text_message,
                        "html": html_message
                     }
                    },
                 "savecopy":1
                }]

        return self.jsonrpc(self.endpoints['mail'], 'SendMessage', params, options)
Esempio n. 5
0
    def sendmessage(self, message, options={}):
        result = error = None

        profile = self.account.get('profile', {})
        from_email = from_ = profile['emails'][0]['value']
        fullname = profile.get('displayName', None)
        if fullname:
            from_email = '"%s" <%s>' % (Header(fullname, 'utf-8').encode(), Header(from_, 'utf-8').encode(),)

        url = "https://mail.google.com/mail/b/%s/smtp/" % from_
        # 'to' parsing
        address_list = AddressList(options.get('to', ''))
        if len(address_list)==0:
            return None, {
                "provider": self.host,
                "message": "recipient address must be specified",
                "status": 0
            }
        to_headers = []
        for addr in address_list:
            if not addr[1] or not '@' in addr[1]:
                return None, {
                    "provider": self.host,
                    "message": "recipient address '%s' is invalid" % (addr[1],),
                    "status": 0
                }
            if addr[0]:
                to_ = '"%s" <%s>' % (Header(addr[0], 'utf-8').encode(), Header(addr[1], 'utf-8').encode())
            else:
                to_ = Header(addr[1], 'utf-8').encode()
            to_headers.append(to_)
        assert to_headers # we caught all cases where it could now be empty.

        server = SMTP(self.host, self.port)
        # in the app:main set debug = true to enable
        if asbool(config.get('debug', False)):
            server.set_debuglevel(True)

        subject = options.get('subject', config.get('share_subject', 'A web link has been shared with you'))
        title = options.get('title', options.get('link', options.get('shorturl', '')))
        description = options.get('description', '')[:280]

        msg = MIMEMultipart('alternative')
        msg.set_charset('utf-8')
        msg.add_header('Subject', Header(subject, 'utf-8').encode())
        msg.add_header('From', from_email)
        for to_ in to_headers:
            msg.add_header('To', to_)

        c.safeHTML = safeHTML
        c.options = options

        # insert the url if it is not already in the message
        c.longurl = options.get('link')
        c.shorturl = options.get('shorturl')

        # reset to unwrapped for html email, they will be escaped
        c.from_name = fullname
        c.subject = subject
        c.from_header = from_
        c.title = title
        c.description = description
        c.message = message

        c.thumbnail = (options.get('picture_base64', "") != "")

        if c.thumbnail:
            part2 = MIMEMultipart('related')

            html = MIMEText(render('/html_email.mako').encode('utf-8'), 'html')
            html.set_charset('utf-8')

            # FIXME: we decode the base64 data just so MIMEImage can re-encode it as base64
            image = MIMEImage(base64.b64decode(options.get('picture_base64')), 'png')
            image.add_header('Content-Id', '<thumbnail>')
            image.add_header('Content-Disposition', 'inline; filename=thumbnail.png')

            part2.attach(html)
            part2.attach(image)
        else:
            part2 = MIMEText(render('/html_email.mako').encode('utf-8'), 'html')
            part2.set_charset('utf-8')


        # get the title, or the long url or the short url or nothing
        # wrap these in literal for text email
        c.from_name = literal(fullname)
        c.subject = literal(subject)
        c.from_header = literal(from_)
        c.title = literal(title)
        c.description = literal(description)
        c.message = literal(message)

        part1 = MIMEText(render('/text_email.mako').encode('utf-8'), 'plain')
        part1.set_charset('utf-8')

        msg.attach(part1)
        msg.attach(part2)

        try:
            try:
                try:
                    server.starttls()
                except smtplib.SMTPException:
                    logger.info("smtp server does not support TLS")
                try:
                    server.ehlo_or_helo_if_needed()
                    server.authenticate(url, self.consumer, self.oauth_token)
                    server.sendmail(from_, to_headers, msg.as_string())
                except smtplib.SMTPRecipientsRefused, exc:
                    for to_, err in exc.recipients.items():
                        error = {"provider": self.host,
                                 "message": err[1],
                                 "status": err[0]
                                }
                        break
                except smtplib.SMTPException, exc:
                    error = {"provider": self.host,
                             "message": "%s: %s" % (exc.smtp_code, exc.smtp_error),
                             "status": exc.smtp_code
                            }
                except UnicodeEncodeError, exc:
                    raise
Esempio n. 6
0
    def sendmessage(self, message, options={}):
        result = error = None

        profile = self.account.get('profile', {})
        from_email = from_ = profile.get('verifiedEmail')
        fullname = profile.get('displayName', None)

        to_addrs = AddressList(options.get('to', None))
        if not to_addrs.addresslist:
            return None, {
                "provider": domain,
                "message": "recipient address is invalid",
                "status": 0
            }

        subject = options.get('subject', config.get('share_subject', 'A web link has been shared with you'))
        title = options.get('title', options.get('link', options.get('shorturl', '')))
        description = options.get('description', '')[:280]
        
        to_ = []
        for a in to_addrs.addresslist:
            # expect normal email address formats, parse them
            to_.append({'name': a[0], 'email': a[1]})

        c.safeHTML = safeHTML
        c.options = options

        # insert the url if it is not already in the message
        c.longurl = options.get('link')
        c.shorturl = options.get('shorturl')


        # reset to unwrapped for html email, they will be escaped
        c.from_name = fullname
        c.subject = subject
        c.from_header = from_
        c.to_header = to_
        c.title = title
        c.description = description
        c.message = message
        c.thumbnail = False

        html_message = render('/html_email.mako').encode('utf-8')

        # get the title, or the long url or the short url or nothing
        # wrap these in literal for text email
        c.from_name = literal(fullname)
        c.subject = literal(subject)
        c.from_header = literal(from_)
        c.to_header = literal(to_)
        c.title = literal(title)
        c.description = literal(description)
        c.message = literal(message)

        text_message = render('/text_email.mako').encode('utf-8')

        params = [{
                "message":
                    {"subject":subject,
                     "from":{"name": fullname, "email":from_},
                     "to":to_,
                     "simplebody":{
                        "text": text_message,
                        "html": html_message
                     }
                    },
                 "savecopy":1
                }]

        return self.jsonrpc(self.endpoints['mail'], 'SendMessage', params, options)
Esempio n. 7
0
    def sendmessage(self, message, options={}):
        share_type = str(options.get('shareType', ''))

        # TODO: this needs a bit work, it is not really "direct".
        if share_type in ('public', 'myConnections'):
            direct = options.get('to', 'anyone')
            if (share_type == 'public' and direct != 'anyone') or \
               (share_type == 'myConnections' and direct != 'connections-only'):
                return None, {'code': 400,
                              'provider': 'linkedin',
                              'message': 'Incorrect addressing for post'}
            url = "http://api.linkedin.com/v1/people/~/shares"
            body = {
                "comment": message,
                "content": {
                    "title": options.get('subject', ''),
                    "submitted-url": options.get('link', ''),
                    "submitted-image-url": options.get('picture', ''),
                    "description": options.get('description', ''),
                },
                "visibility": {
                    "code": direct
                }
            }
        else:
            # we have to do a direct message, different api
            url = "http://api.linkedin.com/v1/people/~/mailbox"

            profile = self.account.get('profile', {})
            from_email = from_ = profile.get('verifiedEmail')
            fullname = profile.get('displayName', None)

            to_addrs = AddressList(options['to'])
            subject = options.get('subject', config.get('share_subject', 'A web link has been shared with you'))
            title = options.get('title', options.get('link', options.get('shorturl', '')))
            description = options.get('description', '')[:280]

            to_ = []
            ids = [a[1] for a in to_addrs.addresslist]
            if not ids:
                return None, {'code': 400,
                              'message': 'Missing contacts for direct messaging.'}
            for id in ids:
                to_.append({'person': {'_path': '/people/' + id}})

            c.safeHTML = safeHTML
            c.options = options
            
            # insert the url if it is not already in the message
            c.longurl = options.get('link')
            c.shorturl = options.get('shorturl')
            
            # get the title, or the long url or the short url or nothing
            # wrap these in literal for text email
            c.from_name = literal(fullname)
            c.subject = literal(subject)
            c.from_header = literal(from_)
            c.to_header = literal(to_)
            c.title = literal(title)
            c.description = literal(description)
            c.message = literal(message)
    
            text_message = render('/text_email.mako').encode('utf-8')
            
            body = { 
                'recipients': {'values': to_},
                'subject': subject,
                'body': text_message
            }
        return self.rawcall(url, body, method="POST")
Esempio n. 8
0
    def sendmessage(self, message, options={}):
        result = error = None

        profile = self.account.get('profile', {})
        from_email = from_ = profile['emails'][0]['value']
        fullname = profile.get('displayName', None)
        if fullname:
            from_email = '"%s" <%s>' % (Header(fullname, 'utf-8').encode(), Header(from_, 'utf-8').encode(),)

        url = "https://mail.google.com/mail/b/%s/smtp/" % from_
        to_ = options.get('to', None)
        if not to_ or not '@' in to_:
            return None, {
                "provider": self.host,
                "message": "recipient address is invalid",
                "status": 0
            }
        to_ = parseaddr(to_)
        if to_[0]:
            to_ = '"%s" <%s>' % (Header(to_[0], 'utf-8').encode(), Header(to_[1], 'utf-8').encode())
        else:
            to_ = Header(to_[1], 'utf-8').encode()

        server = SMTP(self.host, self.port)
        # in the app:main set debug = true to enable
        if asbool(config.get('debug', False)):
            server.set_debuglevel(True)

        subject = options.get('subject', config.get('share_subject', 'A web link has been shared with you'))
        title = options.get('title', options.get('link', options.get('shorturl', '')))
        description = options.get('description', '')[:280]

        msg = MIMEMultipart('alternative')
        msg.set_charset('utf-8')
        msg.add_header('Subject', Header(subject, 'utf-8').encode())
        msg.add_header('From', from_email)
        msg.add_header('To', to_)

        c.safeHTML = safeHTML
        c.options = options

        # insert the url if it is not already in the message
        c.longurl = options.get('link')
        c.shorturl = options.get('shorturl')


        # reset to unwrapped for html email, they will be escaped
        c.from_name = fullname
        c.subject = subject
        c.from_header = from_
        c.to_header = to_
        c.title = title
        c.description = description
        c.message = message

        c.thumbnail = (options.get('picture_base64', "") != "")

        if c.thumbnail:
            part2 = MIMEMultipart('related')

            html = MIMEText(render('/html_email.mako').encode('utf-8'), 'html')
            html.set_charset('utf-8')

            # FIXME: we decode the base64 data just so MIMEImage can re-encode it as base64
            image = MIMEImage(base64.b64decode(options.get('picture_base64')), 'png')
            image.add_header('Content-Id', '<thumbnail>')
            image.add_header('Content-Disposition', 'inline; filename=thumbnail.png')

            part2.attach(html)
            part2.attach(image)
        else:
            part2 = MIMEText(render('/html_email.mako').encode('utf-8'), 'html')
            part2.set_charset('utf-8')


        # get the title, or the long url or the short url or nothing
        # wrap these in literal for text email
        c.from_name = literal(fullname)
        c.subject = literal(subject)
        c.from_header = literal(from_)
        c.to_header = literal(to_)
        c.title = literal(title)
        c.description = literal(description)
        c.message = literal(message)

        part1 = MIMEText(render('/text_email.mako').encode('utf-8'), 'plain')
        part1.set_charset('utf-8')

        msg.attach(part1)
        msg.attach(part2)

        try:
            try:
                try:
                    server.starttls()
                except smtplib.SMTPException:
                    logger.info("smtp server does not support TLS")
                try:
                    server.ehlo_or_helo_if_needed()
                    server.authenticate(url, self.consumer, self.oauth_token)
                    server.sendmail(from_, to_, msg.as_string())
                except smtplib.SMTPRecipientsRefused, exc:
                    for to_, err in exc.recipients.items():
                        error = {"provider": self.host,
                                 "message": err[1],
                                 "status": err[0]
                                }
                        break
                except smtplib.SMTPException, exc:
                    error = {"provider": self.host,
                             "message": "%s: %s" % (exc.smtp_code, exc.smtp_error),
                             "status": exc.smtp_code
                            }
                except UnicodeEncodeError, exc:
                    raise
Esempio n. 9
0
    def sendmessage(self, message, options={}):
        share_type = str(options.get("shareType", ""))

        # TODO: this needs a bit work, it is not really "direct".
        if share_type in ("public", "myConnections"):
            direct = options.get("to", "anyone")
            if (share_type == "public" and direct != "anyone") or (
                share_type == "myConnections" and direct != "connections-only"
            ):
                return None, {"code": 400, "provider": "linkedin", "message": "Incorrect addressing for post"}
            url = "http://api.linkedin.com/v1/people/~/shares"
            body = {
                "comment": message,
                "content": {
                    "title": options.get("subject", ""),
                    "submitted-url": options.get("link", ""),
                    "submitted-image-url": options.get("picture", ""),
                    "description": options.get("description", ""),
                },
                "visibility": {"code": direct},
            }
        else:
            # we have to do a direct message, different api
            url = "http://api.linkedin.com/v1/people/~/mailbox"

            profile = self.account.get("profile", {})
            from_email = from_ = profile.get("verifiedEmail")
            fullname = profile.get("displayName", None)

            to_addrs = AddressList(options["to"])
            subject = options.get("subject", config.get("share_subject", "A web link has been shared with you"))
            title = options.get("title", options.get("link", options.get("shorturl", "")))
            description = options.get("description", "")[:280]

            to_ = []
            ids = [a[1] for a in to_addrs.addresslist]
            if not ids:
                return None, {"code": 400, "message": "Missing contacts for direct messaging."}
            for id in ids:
                to_.append({"person": {"_path": "/people/" + id}})

            c.safeHTML = safeHTML
            c.options = options

            # insert the url if it is not already in the message
            c.longurl = options.get("link")
            c.shorturl = options.get("shorturl")

            # get the title, or the long url or the short url or nothing
            # wrap these in literal for text email
            c.from_name = literal(fullname)
            c.subject = literal(subject)
            c.from_header = literal(from_)
            c.to_header = literal(to_)
            c.title = literal(title)
            c.description = literal(description)
            c.message = literal(message)

            text_message = render("/text_email.mako").encode("utf-8")

            body = {"recipients": {"values": to_}, "subject": subject, "body": text_message}
        return self.rawcall(url, body, method="POST")
Esempio n. 10
0
File: yahoo_.py Progetto: anantn/f1
    def sendmessage(self, message, options={}):
        result = error = None

        profile = self.account.get("profile", {})
        from_email = from_ = profile.get("verifiedEmail")
        fullname = profile.get("displayName", None)

        to_addrs = AddressList(options["to"])
        subject = options.get("subject", config.get("share_subject", "A web link has been shared with you"))
        title = options.get("title", options.get("link", options.get("shorturl", "")))
        description = options.get("description", "")[:280]

        to_ = []
        for a in to_addrs.addresslist:
            # expect normal email address formats, parse them
            to_.append({"name": a[0], "email": a[1]})

        c.safeHTML = safeHTML
        c.options = options

        # insert the url if it is not already in the message
        c.longurl = options.get("link")
        c.shorturl = options.get("shorturl")

        # reset to unwrapped for html email, they will be escaped
        c.from_name = fullname
        c.subject = subject
        c.from_header = from_
        c.to_header = to_
        c.title = title
        c.description = description
        c.message = message
        c.thumbnail = False

        html_message = render("/html_email.mako").encode("utf-8")

        # get the title, or the long url or the short url or nothing
        # wrap these in literal for text email
        c.from_name = literal(fullname)
        c.subject = literal(subject)
        c.from_header = literal(from_)
        c.to_header = literal(to_)
        c.title = literal(title)
        c.description = literal(description)
        c.message = literal(message)

        text_message = render("/text_email.mako").encode("utf-8")

        params = [
            {
                "message": {
                    "subject": subject,
                    "from": {"name": fullname, "email": from_},
                    "to": to_,
                    "simplebody": {"text": text_message, "html": html_message},
                },
                "savecopy": 1,
            }
        ]

        return self.jsonrpc(self.endpoints["mail"], "SendMessage", params, options)
Esempio n. 11
0
    def sendmessage(self, message, options={}):
        result = error = None

        profile = self.account.get('profile', {})
        from_email = from_ = profile['emails'][0]['value']
        fullname = profile.get('displayName', None)
        if fullname:
            from_email = '"%s" <%s>' % (Header(fullname, 'utf-8').encode(), from_,)

        url = "https://mail.google.com/mail/b/%s/smtp/" % from_
        to_ = options['to']
        server = SMTP(self.host, self.port)
        # in the app:main set debug = true to enable
        if asbool(config.get('debug', False)):
            server.set_debuglevel(True)
        
        subject = options.get('subject', config.get('share_subject', 'A web link has been shared with you'))
        title = options.get('title', options.get('link', options.get('shorturl', '')))
        description = options.get('description', '')[:280]

        msg = MIMEMultipart('alternative')
        msg.set_charset('utf-8')
        msg.add_header('Subject', Header(subject, 'utf-8').encode())
        msg.add_header('From', from_email)
        msg.add_header('To', to_)

        c.safeHTML = safeHTML
        c.options = options

        # insert the url if it is not already in the message
        c.longurl = options.get('link')
        c.shorturl = options.get('shorturl')


        # reset to unwrapped for html email, they will be escaped
        c.from_name = fullname
        c.subject = subject
        c.from_header = from_
        c.to_header = to_
        c.title = title
        c.description = description
        c.message = message

        part2 = MIMEText(render('/html_email.mako').encode('utf-8'), 'html')
        part2.set_charset('utf-8')

        # get the title, or the long url or the short url or nothing
        # wrap these in literal for text email
        c.from_name = literal(fullname)
        c.subject = literal(subject)
        c.from_header = literal(from_)
        c.to_header = literal(to_)
        c.title = literal(title)
        c.description = literal(description)
        c.message = literal(message)

        part1 = MIMEText(render('/text_email.mako').encode('utf-8'), 'plain')
        part1.set_charset('utf-8')

        msg.attach(part1)
        msg.attach(part2)

        try:
            try:
                try:
                    server.starttls()
                except smtplib.SMTPException:
                    logger.info("smtp server does not support TLS")
                try:
                    server.ehlo_or_helo_if_needed()
                    server.authenticate(url, self.consumer, self.oauth_token)
                    server.sendmail(from_, to_, msg.as_string())
                except UnicodeEncodeError, exc:
                    raise
                except ValueError, exc:
                    error = {"provider": self.host,
                             "message": "%s: %s" % (exc.smtp_code, exc.smtp_error),
                             "status": exc.smtp_code
                            }
            finally:
                server.quit()
Esempio n. 12
0
    def sendmessage(self, message, options={}):
        result = error = None

        profile = self.account.get('profile', {})
        from_email = from_ = profile.get('verifiedEmail')
        fullname = profile.get('displayName', None)

        to_addrs = AddressList(options['to'])
        subject = options.get('subject', config.get('share_subject', 'A web link has been shared with you'))
        title = options.get('title', options.get('link', options.get('shorturl', '')))
        description = options.get('description', '')[:280]
        
        to_ = []
        for a in to_addrs.addresslist:
            # expect normal email address formats, parse them
            to_.append({'name': a[0], 'email': a[1]})

        c.safeHTML = safeHTML
        c.options = options

        # insert the url if it is not already in the message
        c.longurl = options.get('link')
        c.shorturl = options.get('shorturl')


        # reset to unwrapped for html email, they will be escaped
        c.from_name = fullname
        c.subject = subject
        c.from_header = from_
        c.to_header = to_
        c.title = title
        c.description = description
        c.message = message

        html_message = render('/html_email.mako').encode('utf-8')

        # get the title, or the long url or the short url or nothing
        # wrap these in literal for text email
        c.from_name = literal(fullname)
        c.subject = literal(subject)
        c.from_header = literal(from_)
        c.to_header = literal(to_)
        c.title = literal(title)
        c.description = literal(description)
        c.message = literal(message)

        text_message = render('/text_email.mako').encode('utf-8')

        params = [{
                "message":
                    {"subject":subject,
                     "from":{"name": fullname, "email":from_},
                     "to":to_,
                     "simplebody":{
                        "text": text_message,
                        "html": html_message
                     }
                    },
                 "savecopy":1
                }]

        return self.rawcall(self.endpoints['mail'], 'SendMessage', params, options)