Ejemplo n.º 1
0
    def testHTMLEmail(self):
        mailto = '*****@*****.**'
        mailfrom = '*****@*****.**'

        msg = MIMEMultipart('alternative')
        msg['Subject'] = 'HTML/Text Email Test'
        msg['From'] = mailto
        msg['To'] = mailfrom

        text = 'This is the text body'
        html = "<html><body><p>This is the html body</p></body></html>"

        msg.attach(MIMEText(text, 'plain'))
        msg.attach(MIMEText(text, 'plain'))
        msg.attach(MIMEText(html, 'html'))

        # Send the message via our own SMTP server
        s = smtplib.SMTP('localhost', 8181)
        s.sendmail(mailfrom, mailto, msg.as_string())
        s.quit()
        result_text = text
        result_text += '%s' % '=' * 80
        result_text += text

        self.assertEquals(Message().get(1)['text_body'], result_text)
        self.assertEquals(Message().get(1)['html_body'], html)
Ejemplo n.º 2
0
def process_request(request):
    try:
        result_set = Message().order_by('received_date DESC').all()
    except:
        result_set = False

    return HttpRenderResponse('index.html', {'rows': result_set})
Ejemplo n.º 3
0
 async def message_handler(self, message: str, user: '******'):
     message_obj = Message.create(user, message)
     serialized_message = message_obj.serialize()
     message_to_send = {
         'type': 'receive_message',
         'message': serialized_message
     }
     debug_log(message_to_send)
     await self.send_to_all_clients(message_to_send)
Ejemplo n.º 4
0
 def setUp(self):
     # Create the db and a message
     check_table_exists()
     Message().save(mail_from='*****@*****.**',
                    mail_to='*****@*****.**',
                    subject='unittest',
                    text_body='The Text Body',
                    html_body='The HTML Body',
                    original='Original Content')
Ejemplo n.º 5
0
    def testTextEmail(self):
        mailto = '*****@*****.**'
        mailfrom = '*****@*****.**'

        msg = MIMEText('This is a test email message')
        msg['Subject'] = 'Email Test'
        msg['From'] = mailto
        msg['To'] = mailfrom

        # Send the message via our test SMTP server
        s = smtplib.SMTP('localhost', 8181)
        s.sendmail(mailfrom, mailto, msg.as_string())
        s.quit()
        self.assertEquals(Message().get(1)['subject'], 'Email Test')
Ejemplo n.º 6
0
Archivo: delete.py Proyecto: junlly/TMS
def process_request(request):
    try:
        message_id = int(request.parsed_query['id'][0])

        if message_id <= 0:
            raise Exception

        Message().delete(message_id)

        return HttpResponseRedirect('/')
    except:
        return HttpRenderResponse(
            'error.html',
            {'error_msg': 'Please select an email message from the list.'})
Ejemplo n.º 7
0
Archivo: server.py Proyecto: junlly/TMS
    def process_message(self, peer, mailfrom, rcpttos, data):
        try:
            msg = email.message_from_string(data)
            text_body = ''
            html_body = ''

            if msg.get_content_maintype() == 'multipart':
                for part in msg.get_payload():
                    if part.get_content_type() == 'text/html':
                        try:
                            html_body = part.get_payload(decode=True)
                            html_body = html_body.decode(
                                part.get_content_charset())
                        except:
                            print "Unable to decode html email"
                    else:
                        if (text_body != ''):
                            text_body += '%s' % '=' * 80
                        try:
                            text_body += part.get_payload(decode=True)
                            text_body = text_body.decode(
                                part.get_content_charset())
                        except:
                            print "Unable to decode text email"

            elif msg.get_content_maintype() == 'text':
                text_body = msg.get_payload(decode=True)

            Message().save(
                mail_from=msg['from'],
                mail_to=msg['to'],
                content_type=msg.get_content_type(),
                subject=msg['subject'],
                text_body=text_body,
                html_body=html_body,
                original=data,
                received_date=datetime.now().strftime("%Y-%m-%d %H:%M:%S"))

            print '%s' % '=' * 80
            print 'New email added to database (To: %s; Subject: %s) ' % (
                msg['to'], msg['subject'])
        except Exception, e:
            print e
Ejemplo n.º 8
0
def process_request(request):
    try:
        message_id = int(request.parsed_query['id'][0])

        if message_id <= 0:
            raise Exception

        try:
            result = Message().get(message_id)
        except ModelException:
            raise Exception('Email message not found')

        if request.parsed_query.has_key('onlymsg') == True:
            return result['html_body']

        return HttpRenderResponse('message.html', {'message': result})
    except Exception:
        return HttpRenderResponse(
            'error.html',
            {'error_msg': 'Please select an email message from the list.'})
Ejemplo n.º 9
0
    def testDB(self):
        check_table_exists()
        self.assertTrue(path.exists('temp.db'))

        Message().save(mail_from='*****@*****.**',
                       mail_to='*****@*****.**',
                       subject='unittest')

        self.assertEquals(Message().get(1)['mail_from'], '*****@*****.**')

        Message().save(mail_from='*****@*****.**',
                       mail_to='*****@*****.**',
                       subject='second unittest')

        Message().save(message_id=1,
                       mail_from='*****@*****.**',
                       mail_to='*****@*****.**',
                       subject='unittest')

        self.assertEquals(len(Message().all()), 2)

        self.assertEquals(
            Message().order_by('message_id DESC').all()[0]['subject'],
            'second unittest')

        Message().delete(1)
        self.assertRaises(ModelException, Message().get, 1)

        Message().delete(2)
        self.assertRaises(ModelException, Message().all)

        self.assertRaises(ModelException, Message().save, bad_key=True)

        settings.DELETE_DB_ON_EXIT = True
        delete_db()
        self.assertFalse(path.exists('temp.db'))