Exemplo n.º 1
0
    def send_txt(cls,
                 sender,
                 recipients,
                 subject,
                 text,
                 servername='',
                 options=None):
        '''
        Sends a plain-text message. Accepts either Unicode or UTF-8 encoded strings

        >>> MailgunMessage.send_text("*****@*****.**",
            "*****@*****.**",
            "Hello",
            "Hi!\nI am sending the message using Mailgun")
        '''
        params = to_unicode(
            dict(sender=sender,
                 recipients=recipients,
                 subject=subject,
                 body=text))
        if options:
            params['options'] = simplejson.dumps(options)
        request = _Request(cls._messages_url('txt', servername))
        request.add_data(urllib.urlencode(to_utf_8(params)))
        _post(request)
Exemplo n.º 2
0
    def upsert_from_csv(cls, mailboxes):
        '''
        Upsert mailboxes contained in a csv string,

        [email protected], password
        [email protected], password2
        '''
        request = _Request("{0}/mailboxes.txt?api_key={1}".format(MailgunResource._site, MailgunResource._password))
        request.add_data(mailboxes)
        request.add_header("Content-Type", "text/plain")
        _post(request)
Exemplo n.º 3
0
 def upsert_from_csv(cls, mailboxes):
     '''
     Upsert mailboxes contained in a csv string,
     
     [email protected], password
     [email protected], password2         
     '''
     request = _Request("{0}/mailboxes.txt?api_key={1}".format(
         MailgunResource._site, MailgunResource._password))
     request.add_data(mailboxes)
     request.add_header("Content-Type", "text/plain")
     _post(request)
Exemplo n.º 4
0
    def send_txt(cls, sender, recipients, subject, text, servername='', options = None):
        '''
        Sends a plain-text message. Accepts either Unicode or UTF-8 encoded strings

        >>> MailgunMessage.send_text("*****@*****.**",
            "*****@*****.**",
            "Hello",
            "Hi!\nI am sending the message using Mailgun")
        '''
        params = to_unicode(dict(sender=sender, recipients=recipients, subject=subject, body=text))
        if options:
            params['options'] = simplejson.dumps(options)
        request = _Request(cls._messages_url('txt', servername))
        request.add_data(urllib.urlencode(to_utf_8(params)))
        _post(request)
Exemplo n.º 5
0
    def send_raw(cls, sender, recipients, mime_body, servername=''):
        '''
        Sends a raw MIME message. Accepts either Unicode or UTF-8 encoded strings

        >>> Mailgun.init("api-key-dirty-secret")
        >>> raw_mime = "X-Priority: 1 (Highest)\n"\
                "Content-Type: text/plain;charset=utf-8\n"\
                "Subject: Hello!\n"\
                "\n"\
                "I construct MIME message and send it!"
        >>> MailgunMessage.send_raw("*****@*****.**", "*****@*****.**", raw_mime)
        '''
        request = _Request(cls._messages_url('eml', servername))
        request.add_data(u"{0}\n{1}\n\n{2}".format(*to_unicode([sender, recipients, mime_body])).encode("utf-8"))
        request.add_header("Content-Type", "text/plain")
        _post(request)
Exemplo n.º 6
0
 def send_raw(cls, sender, recipients, mime_body, servername=''):
     '''
     Sends a raw MIME message
     
     >>> Mailgun.init("api-key-dirty-secret")
     >>> raw_mime = "X-Priority: 1 (Highest)\n"\
             "Content-Type: text/plain;charset=utf-8\n"\
             "Subject: Hello!\n"\
             "\n"\
             "I construct MIME message and send it!"
     >>> MailgunMessage.send_raw("*****@*****.**", "*****@*****.**", raw_mime)        
     '''
     request = _Request(cls._messages_url('eml', servername))
     request.add_data("{0}\n{1}\n\n{2}".format(sender, recipients,
                                               mime_body))
     request.add_header("Content-Type", "text/plain")
     _post(request)