Ejemplo n.º 1
0
 def fillresponse(self):
     legal = LegalEntity.objects.get(id=1)
     if self.getparam('CONFIRME') is None:
         dlg = self.create_custom()
         img = XferCompImage('img')
         img.set_value(self.icon_path())
         img.set_location(0, 0, 1, 3)
         dlg.add_component(img)
         lbl = XferCompLabelForm('lbl_title')
         lbl.set_location(1, 0, 2)
         lbl.set_value_as_header(self.caption)
         dlg.add_component(lbl)
         email = XferCompEdit('recipient')
         email.set_location(1, 1)
         email.set_value(legal.email)
         email.mask = r"[^@]+@[^@]+\.[^@]+"
         email.description = _("email")
         dlg.add_component(email)
         dlg.add_action(self.get_action(TITLE_OK, "images/ok.png"),
                        close=CLOSE_YES,
                        params={'CONFIRME': 'YES'})
         dlg.add_action(WrapAction(TITLE_CANCEL, 'images/cancel.png'))
     else:
         abs_url = self.request.META.get(
             'HTTP_REFERER', self.request.build_absolute_uri()).split('/')
         self.item.http_root_address = '/'.join(abs_url[:-2])
         send_email([self.getparam('recipient')],
                    self.item.subject,
                    self.item.email_content,
                    files=self.item.attach_files)
         self.message(_("EMail send, check it."))
Ejemplo n.º 2
0
 def test_send_withdouble(self):
     configSMTP('localhost', 1025)
     self.assertEqual(0, self.server.count())
     self.assertEqual(True, will_mail_send())
     send_email(
         ['*****@*****.**', '*****@*****.**', '*****@*****.**'],
         'send correct config',
         'Yessss!!!',
         cclist=['*****@*****.**', '*****@*****.**', '*****@*****.**'],
         bcclist=['*****@*****.**', '*****@*****.**', '*****@*****.**'])
     self.assertEqual(1, self.server.count())
     self.assertEqual('*****@*****.**',
                      self.server.get(0)[1])
     self.assertEqual([
         '*****@*****.**', '*****@*****.**', '*****@*****.**',
         '*****@*****.**', '*****@*****.**', '*****@*****.**'
     ],
                      self.server.get(0)[2])
     msg, = self.server.check_first_message(
         'send correct config', 1, {
             'To': '[email protected], [email protected], [email protected]',
             'Cc': '[email protected], [email protected]'
         })
     self.assertEqual('text/plain', msg.get_content_type())
     self.assertEqual('base64', msg.get('Content-Transfer-Encoding', ''))
     self.assertEqual('Yessss!!!', decode_b64(msg.get_payload()))
     self.assertEqual(None, self.server.smtp.auth_params)
Ejemplo n.º 3
0
 def sendemail(self, nb_to_send, http_root_address):
     if will_mail_send() and (self.status == 2):
         email_list = self.email_to_send.split("\n")
         link_html = ""
         files = []
         for doc in self.documents.all():
             if self.doc_in_link:
                 if doc.sharekey is None:
                     doc.change_sharekey(False)
                     doc.save()
                 doc.set_context(http_root_address)
                 link_html += "<li><a href='%s'>%s</a></li>" % (doc.shared_link, doc.name)
             else:
                 files.append((doc.name, doc.content))
         if self.doc_in_link and (link_html != ''):
             link_html = "<hr/><h3>%s</h3><ul>%s</ul>" % (_('Shared documents'), link_html)
         email_content = "<html><body>%s%s</body></html>" % (toHtml(self.body), link_html)
         for contact_email in email_list[:nb_to_send]:
             contact_id, email = contact_email.split(':')
             try:
                 contact = AbstractContact.objects.get(id=contact_id)
             except AbstractContact.DoesNotExist:
                 contact = None
             try:
                 send_email([email], self.subject, email_content, files=files if len(files) > 0 else None)
                 EmailSent.objects.create(message=self, contact=contact, email=email, date=timezone.now(), success=True)
             except Exception as error:
                 EmailSent.objects.create(message=self, contact=contact, email=email, date=timezone.now(), success=False, error=six.text_type(error))
         self.email_to_send = "\n".join(email_list[nb_to_send:])
         if self.email_to_send == '':
             self.status = 1
         self.save()
     return
Ejemplo n.º 4
0
 def test_send_with_files(self):
     file1 = BytesIO(get_binay('blablabla\blabla.'))
     file2 = open(join(dirname(__file__), 'static', 'lucterios.mailing',
                       'images', 'config_mail.png'),
                  mode='rb')
     try:
         configSMTP('localhost', 1025)
         self.assertEqual(0, self.server.count())
         self.assertEqual(True, will_mail_send())
         send_email('*****@*****.**', 'send with files', '2 files sent!',
                    [('filename1.txt', file1), ('filename2.png', file2)])
         self.assertEqual(1, self.server.count())
         self.assertEqual('*****@*****.**',
                          self.server.get(0)[1])
         self.assertEqual(['*****@*****.**'], self.server.get(0)[2])
         msg, msg_f1, msg_f2 = self.server.check_first_message(
             'send with files', 3)
         self.assertEqual('text/plain', msg.get_content_type())
         self.assertEqual('base64', msg.get('Content-Transfer-Encoding',
                                            ''))
         self.assertEqual('2 files sent!', decode_b64(msg.get_payload()))
         self.assertEqual(None, self.server.smtp.auth_params)
         self.assertTrue('filename1.txt' in msg_f1.get('Content-Type', ''),
                         msg_f1.get('Content-Type', ''))
         self.assertEqual('blablabla\blabla.',
                          decode_b64(msg_f1.get_payload()))
         self.assertTrue('filename2.png' in msg_f2.get('Content-Type', ''),
                         msg_f2.get('Content-Type', ''))
         file2.seek(0, SEEK_END)
         self.assertEqual(file2.tell(),
                          len(b64decode(msg_f2.get_payload())))
     finally:
         file1.close()
         file2.close()
Ejemplo n.º 5
0
 def test_send_no_config(self):
     configSMTP('', 25)
     self.assertEqual(0, self.server.count())
     self.assertEqual(False, will_mail_send())
     try:
         send_email('*****@*****.**', 'send without config', 'boom!!!')
         self.assertTrue(False)
     except LucteriosException as error:
         self.assertEqual(six.text_type(error), 'Courriel non configuré!')
     self.assertEqual(0, self.server.count())
Ejemplo n.º 6
0
 def test_send_with_ssl(self):
     configSMTP('localhost', 1025, 2)
     self.assertEqual(0, self.server.count())
     self.assertEqual(True, will_mail_send())
     try:
         send_email('*****@*****.**', 'send with ssl', 'not success!')
         self.assertTrue(False)
     except LucteriosException as error:
         self.assertTrue('unknown protocol' in six.text_type(error),
                         six.text_type(error))
     self.assertEqual(0, self.server.count())
Ejemplo n.º 7
0
 def test_send_with_starttls(self):
     configSMTP('localhost', 1025, 1)
     self.assertEqual(0, self.server.count())
     self.assertEqual(True, will_mail_send())
     try:
         send_email('*****@*****.**', 'send with starttls', 'failed!')
         self.assertTrue(False)
     except LucteriosException as error:
         self.assertEqual(six.text_type(error),
                          'STARTTLS extension not supported by server.')
     self.assertEqual(0, self.server.count())
Ejemplo n.º 8
0
 def test_send_bad_config(self):
     configSMTP('localhost', 1125)
     self.assertEqual(0, self.server.count())
     self.assertEqual(True, will_mail_send())
     try:
         send_email('*****@*****.**', 'send without config', 'boom!!!')
         self.assertTrue(False)
     except LucteriosException as error:
         self.assertEqual(six.text_type(error),
                          '[Errno 111] Connection refused')
     self.assertEqual(0, self.server.count())
Ejemplo n.º 9
0
 def test_send_with_auth(self):
     if six.PY3:
         self.server.smtp.with_authentificate = True
         configSMTP('localhost', 1025, 0, 'toto', 'abc123')
         self.assertEqual(0, self.server.count())
         self.assertEqual(True, will_mail_send())
         send_email('*****@*****.**', 'send with auth', 'OK!')
         self.assertEqual(1, self.server.count())
         msg, = self.server.check_first_message('send with auth', 1)
         self.assertEqual('OK!', decode_b64(msg.get_payload()))
         self.assertEqual(['', 'toto', 'abc123'],
                          self.server.smtp.auth_params)
Ejemplo n.º 10
0
 def fillresponse(self):
     if not will_mail_send():
         raise LucteriosException(IMPORTANT, _('Bad email parameter!'))
     legal = LegalEntity.objects.get(id=1)
     address = []
     address.append("")
     address.append("")
     address.append(six.text_type(legal))
     address.append(legal.address)
     address.append("%s %s" % (legal.postal_code, legal.city))
     send_email(None, _("EMail try"), _('EMail sent to check configuration') +
                "\n".join(address).replace('{[newline]}', "\n").replace('{[br/]}', "\n"))
     self.message(_("EMail send, check it."))
Ejemplo n.º 11
0
 def fillresponse(self):
     if not will_mail_send():
         raise LucteriosException(IMPORTANT, _('Bad email parameter!'))
     legal = LegalEntity.objects.get(id=1)
     address = []
     address.append("")
     address.append("")
     address.append(six.text_type(legal))
     address.append(legal.address)
     address.append("%s %s" % (legal.postal_code, legal.city))
     send_email(None, _("EMail try"), _('EMail sent to check configuration') +
                "\n".join(address).replace('{[newline]}', "\n").replace('{[br/]}', "\n"))
     self.message(_("EMail send, check it."))
Ejemplo n.º 12
0
 def send_email(self):
     nb_sent, nb_failed = 0, 0
     if will_mail_send():
         email_content = "<html><body>%s</body></html>" % toHtml(self.body)
         for contact in self.get_contacts():
             if contact.email != '':
                 try:
                     send_email(
                         [contact.email], self.subject, email_content)
                     nb_sent += 1
                 except:
                     nb_failed += 1
     return nb_sent, nb_failed
Ejemplo n.º 13
0
 def test_send_html(self):
     configSMTP('localhost', 1025)
     self.assertEqual(0, self.server.count())
     self.assertEqual(True, will_mail_send())
     send_email('*****@*****.**', 'send html',
                '<html><body><h1>Yessss!!!</h1></body></html>')
     self.assertEqual(1, self.server.count())
     self.assertEqual('*****@*****.**',
                      self.server.get(0)[1])
     self.assertEqual(['*****@*****.**'], self.server.get(0)[2])
     msg, = self.server.check_first_message('send html', 1)
     self.assertEqual('text/html', msg.get_content_type())
     self.assertEqual('base64', msg.get('Content-Transfer-Encoding', ''))
     self.assertEqual('<html><body><h1>Yessss!!!</h1></body></html>',
                      decode_b64(msg.get_payload()))
Ejemplo n.º 14
0
 def fillresponse(self):
     if not will_mail_send():
         raise LucteriosException(IMPORTANT, _('Bad email parameter!'))
     legal = LegalEntity.objects.get(id=1)
     if self.getparam('CONFIRME') is None:
         dlg = self.create_custom()
         img = XferCompImage('img')
         img.set_value(self.icon_path())
         img.set_location(0, 0, 1, 3)
         dlg.add_component(img)
         lbl = XferCompLabelForm('lbl_title')
         lbl.set_location(1, 0, 2)
         lbl.set_value_as_header(self.caption)
         dlg.add_component(lbl)
         email = XferCompEdit('recipient')
         email.set_location(1, 1)
         email.set_value(legal.email)
         email.mask = r"[^@]+@[^@]+\.[^@]+"
         email.description = _("email")
         dlg.add_component(email)
         dlg.add_action(self.get_action(TITLE_OK, "images/ok.png"), close=CLOSE_YES, params={'CONFIRME': 'YES'})
         dlg.add_action(WrapAction(TITLE_CANCEL, 'images/cancel.png'))
     else:
         address = []
         address.append("")
         address.append("")
         address.append(six.text_type(legal))
         address.append(legal.address)
         address.append("%s %s" % (legal.postal_code, legal.city))
         message = _('EMail sent to check configuration')
         message += "{[br/]}".join(address).replace('{[newline]}', "{[br/]}").replace("\n", '{[br/]}')
         bad_sended = send_email(self.getparam('recipient'), _("EMail try"), "<html><body>%s</body></html>" % message.replace('{[', '<').replace(']}', '>'))
         if len(bad_sended) != 0:
             raise EmailException(bad_sended)
         self.message(_("EMail send, check it."))
Ejemplo n.º 15
0
 def test_send_copyhimself(self):
     configSMTP('localhost', 1025)
     self.assertEqual(0, self.server.count())
     self.assertEqual(True, will_mail_send())
     send_email('*****@*****.**',
                'send correct config',
                'Yessss!!!',
                withcopy=True)
     self.assertEqual(1, self.server.count())
     self.assertEqual('*****@*****.**',
                      self.server.get(0)[1])
     self.assertEqual(['*****@*****.**', '*****@*****.**'],
                      self.server.get(0)[2])
     msg, = self.server.check_first_message('send correct config', 1)
     self.assertEqual('text/plain', msg.get_content_type())
     self.assertEqual('base64', msg.get('Content-Transfer-Encoding', ''))
     self.assertEqual('Yessss!!!', decode_b64(msg.get_payload()))
     self.assertEqual(None, self.server.smtp.auth_params)
Ejemplo n.º 16
0
 def send_email(self, http_root_address):
     getLogger('lucterios.mailing').debug(
         'EmailSent.send_email(http_root_address=%s)', http_root_address)
     try:
         body = self.replace_tag(self.message.email_content)
         h2txt = HTML2Text()
         h2txt.ignore_links = False
         body_txt = h2txt.handle(body)
         if http_root_address != '':
             self.message.http_root_address = http_root_address
             img_html = "<img src='%s/lucterios.mailing/emailSentAddForStatistic?emailsent=%d' alt=''/>" % (
                 http_root_address, self.id)
             body = body.replace('</body>', img_html + '</body>')
         email, ccemail = self.get_emails()
         getLogger('lucterios.mailing').debug('send email %s : %s' %
                                              (self.message.subject, email))
         no_send_list = send_email(split_doubled_email(email),
                                   self.replace_tag(self.message.subject),
                                   body,
                                   files=self.get_attach_files(),
                                   cclist=split_doubled_email(ccemail),
                                   withcopy=self.item is not None,
                                   body_txt=body_txt)
         self.success = True
         if len(no_send_list) > 0:
             email_list = email
             if ccemail is not None:
                 email_list.extend(ccemail)
             for email_item in split_doubled_email(email_list):
                 if email_item not in no_send_list:
                     no_send_list[email_item] = 'OK'
             self.error = six.text_type(no_send_list)
     except Exception as error:
         if getLogger('lucterios.mailing').isEnabledFor(DEBUG):
             getLogger('lucterios.mailing').exception('send_email')
         self.success = False
         self.error = six.text_type(error)
     self.save()