def test_delete_message(self): request = generateHttpRequest() #not find message result = delete_message(request, '20fc43b89e97484aba6fc1870f026a2e') self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'IN003') #find message msg = Message(sender=request.user, sender_site=None, subject="pandas") msg.urgent = False msg.message_type = 'NM' msg.callback_number = '2561234561' msg.save() body = "i am indeed a talking panda. how are you?" msg_body = MessageBody(message=msg, body=body) msg_body.save() mbu = MessageBodyUserStatus(msg_body=msg_body, user=request.user) mbu.save() result = delete_message(request, msg.uuid) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['data'], {})
def testGetReferPDF(self): sender = self.user msg = Message(sender=sender, sender_site=None, subject="pandas") msg.urgent = False msg.message_type = 'NM' msg.callback_number = '2561234561' msg.save() refer = MessageRefer() refer.message = msg refer.gender = 'M' refer.status = 'AC' refer.phone_number = 8529631475 refer.alternative_phone_number = 1472583695 refer.home_phone_number = 8472583695 refer.save() response = self.client.get(reverse('MHLogin.api.v1.views_messaging.getReferPDF', \ args=(refer.uuid,)), **self.extra) self.assertEqual(response.content, err_GE002().content, response.status_code) response = self.client.post(reverse('MHLogin.api.v1.views_messaging.getReferPDF', \ args=(refer.uuid,)), **self.extra) self.assertEqual(response.status_code, 400, response.status_code) with self.assertRaises(Exception): self.client.post(reverse( 'MHLogin.api.v1.views_messaging.getReferPDF', args=(refer.uuid,)), \ data={'secret': 'ABeohIU4Sy48bQ/w07cLKBJ6gv49ptEF0YY48VXSMr4='}, **self.extra)
def test_bad_password(self): self.request.post('/login/', {'username': self.provider.username, 'password': '******'}) sender = authenticate(username=self.provider.username, password='******') msg = Message(sender=sender, sender_site=None, subject="pandas") recipient = User.objects.get(id=self.provider2.id) msg.urgent = False msg.message_type = 'NM' msg.save() body = "i am indeed a talking panda. how are you?" msg_body = msg.save_body(body) MessageRecipient(message=msg, user=recipient).save() self.request.logout() test = CalledTest() models.sendSMS_Twilio_newMessage = test msg.send(self.request, msg_body, []) self.assertTrue(test.was_called) response = self.request.post('/login/', {'username': self.provider2.username, 'password': '******'}) clean_msg_body = MessageBody.objects.get(message=msg) self.request.user = recipient store_user_key(self.request, response, 'wrongpassword') self.request.COOKIES = {'ss': response.cookies['ss'].value} self.assertRaises(KeyInvalidException, clean_msg_body.decrypt, self.request) self.request.logout()
def testGetRefer(self): user = create_user('practicemgr','yang','peng','demo') msg = Message(sender=user, sender_site = None, subject="pandas") msg.urgent = False msg.callback_number = 2561234561 msg.save() refer = MessageRefer() refer.message = msg refer.gender = 'M' refer.status = 'AC' refer.phone_number = 8529631475 refer.alternative_phone_number = 1472583695 refer.home_phone_number = 8472583695 refer.save() refer_list=[refer] self.assertEqual(get_refer(refer_list),refer.status) with self.assertRaises(TypeError):get_refer(refer) #class Get_attachment_filenameTest(TestCase): # def test_get_attachment_filename(self): # user = create_user('practicemgr','yang','peng','demo') # msg = Message(sender=user, sender_site = None, subject="pandas") # msg.urgent = False # msg.callback_number = 2561234561 # msg.save() # request = generateHttpRequest() # msgCon = MessageContent() # msgCon.message=msg # msgCon.save() # attachment = MessageAttachment(msgCon) # attachment.size = '12' # attachment.save() # # _get_attachment_filename(request,msg)
def testDeleteMessage(self): self.user = create_user(get_random_username(), "mhluser", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "") self.user.mdcom_phone = '9002000001' self.user.save() sender = self.user msg = Message(sender=sender, sender_site=None, subject="pandas") msg.urgent = False msg.message_type = 'NM' msg.callback_number = '2561234561' msg.save() body = "i am indeed a talking panda. how are you?" msg_body = MessageBody(message=msg, body=body) msg_body.save() msgbus = MessageBodyUserStatus() msgbus.user = self.user msgbus.msg_body = msg_body msgbus.save() self.msgbus = msgbus self.extra['HTTP_MDCOM_USER_UUID'] = self.user.uuid message_id = msg.uuid response = self.client.get(reverse( 'MHLogin.api.v1.views_messaging.deleteMessage', args=(message_id,)), **self.extra) self.assertEqual(response.status_code, 200, response.status_code)
def test_bad_password(self): self.request.post('/login/', { 'username': self.provider.username, 'password': '******' }) sender = authenticate(username=self.provider.username, password='******') msg = Message(sender=sender, sender_site=None, subject="pandas") recipient = User.objects.get(id=self.provider2.id) msg.urgent = False msg.message_type = 'NM' msg.save() body = "i am indeed a talking panda. how are you?" msg_body = msg.save_body(body) MessageRecipient(message=msg, user=recipient).save() self.request.logout() test = CalledTest() models.sendSMS_Twilio_newMessage = test msg.send(self.request, msg_body, []) self.assertTrue(test.was_called) response = self.request.post('/login/', { 'username': self.provider2.username, 'password': '******' }) clean_msg_body = MessageBody.objects.get(message=msg) self.request.user = recipient store_user_key(self.request, response, 'wrongpassword') self.request.COOKIES = {'ss': response.cookies['ss'].value} self.assertRaises(KeyInvalidException, clean_msg_body.decrypt, self.request) self.request.logout()
def test_invalid_recipient(self): self.request.post('/login/', {'username': self.provider.username, 'password': '******'}) sender = authenticate(username=self.provider.username, password='******') msg = Message(sender=sender, sender_site=None, subject="this was a triumph") recipient = None msg.urgent = False msg.message_type = 'NM' msg.save() body = "i'm making a note here: huge success" msg_body = msg.save_body(body) self.assertRaises(ValueError, MessageRecipient, message=msg, user=recipient) self.assertRaises(InvalidRecipientException, msg.send, self.request, msg_body, []) self.request.logout()
def test_normal_message(self): self.request.post('/login/', { 'username': self.provider.username, 'password': '******' }) sender = authenticate(username=self.provider.username, password='******') msg = Message(sender=sender, sender_site=None, subject="pandas") recipient = User.objects.get(id=self.provider2.id) msg.urgent = False msg.message_type = 'NM' self.assertRaises(Exception, msg.save_body, '') msg.save() body = "i am indeed a talking panda. how are you?" msg_body = msg.save_body(body) MessageRecipient(message=msg, user=recipient).save() test = CalledTest() models.sendSMS_Twilio_newMessage = test msg.send(self.request, msg_body, []) self.assertTrue(test.was_called) self.assertTrue( Message.objects.filter(sender=sender, subject="pandas").exists()) self.assertTrue( MessageRecipient.objects.filter(message=msg, user=recipient).exists()) msg_body.delete() clean_msg_body = MessageBody.objects.get(pk=msg_body.pk) self.request.logout() self.assertEqual(msg_body.decrypt(self.request), body) response = self.request.post('/login/', { 'username': self.provider2.username, 'password': '******' }) self.request.user = authenticate(username=self.provider2.username, password='******') self.request.COOKIES = {'ss': response.cookies['ss'].value} try: self.assertEqual(clean_msg_body.decrypt(self.request), body) except KeyInvalidException: raise self.failureException("message body decryption failed") self.assertRaises(Exception, msg.save) self.assertRaises(Exception, msg.delete, self.request) self.assertRaises(Exception, msg.send, self.request, msg_body, []) self.request.logout()
def testGetMessageLogic(self): request = generateHttpRequest() user = create_user('yangpeng', 'yang', 'peng', 'demo') msg = Message(sender=user, sender_site=None, subject="pandas") msg.urgent = False msg.message_type = 'NM' msg.callback_number = '2561234561' msg.save() message_id = msg.uuid request.method = "get" response = getMessageLogic(request, message_id) self.assertEqual(json.loads(response.content)['errno'], 'GE002') request.method = "POST" with self.assertRaises(Http404): getMessageLogic(request, message_id)
def testUpdateRefer(self): provider = Provider(username="******", first_name="upre", last_name="test", office_lat=0.0, office_longit=0.0) provider.set_password("maestro") provider.save() provider2 = Provider(username="******", first_name="doc", last_name="holiday", office_lat=0.0, office_longit=0.0) provider2.set_password("holiday") provider2.save() sender = provider msg = Message(sender=sender, sender_site=None, subject="pandas") msg.urgent = False msg.message_type = 'NM' msg.callback_number = '2561234561' msg.save() body = "i am indeed a talking panda. how are you?" msg_body = MessageBody(message=msg, body=body) msg_body.save() refer = MessageRefer() refer.message = msg refer.first_name = 'msg' refer.middle_name = 'refer' refer.last_name = 'again' refer.gender = 'M' refer.status = 'NO' refer.phone_number = 8529631475 refer.alternative_phone_number = 1472583695 refer.save() msgRe = MessageRecipient() msgRe.message = msg msgRe.user = provider2 msgRe.save() generate_keys_for_users(output=DevNull()) VMBox_Config(owner=provider).save() VMBox_Config(owner=provider2).save() response = self.client.get(reverse( 'MHLogin.api.v1.views_messaging.updateRefer', args=(refer.uuid,)), **self.extra) self.assertEqual(response.content, err_GE002().content, response.status_code) response = self.client.post(reverse( 'MHLogin.api.v1.views_messaging.updateRefer', args=(refer.uuid,)), \ data={'status': 'NO'}, **self.extra) self.assertEqual(response.status_code, 200, response.status_code) m = json.loads(response.content) self.assertEqual(len(m), 2)
def testGetAttachment(self): sender = self.user msg = Message(sender=sender, sender_site=None, subject="pandas") msg.urgent = False msg.draft = True msg.message_type = 'NM' msg.callback_number = '2561234561' msg.save() # attachment = MessageAttachment() # attachment.size = '12' # attachment.save() # attachment.uuid # response = self.client.get(reverse('MHLogin.api.v1.views_messaging.getAttachment', args=(msg.uuid, msg.uuid)), **self.extra) self.assertEqual(response.content, err_GE002().content, response.status_code)
def testMarkMessageUnread(self): response = self.client.get(reverse( 'MHLogin.api.v1.views_messaging.markMessageUnread'), **self.extra) self.assertEqual(response.content, err_GE002().content, response.status_code) sender = self.user msg = Message(sender=sender, sender_site=None, subject="pandas") msg.urgent = False msg.message_type = 'NM' msg.callback_number = '2561234561' msg.save() message_id = msg.uuid data = {'message_ids': [message_id]} response = self.client.post(reverse( 'MHLogin.api.v1.views_messaging.markMessageUnread'), data, **self.extra) self.assertEqual(response.status_code, 200, response.status_code) msg = json.loads(response.content) self.assertEqual(len(msg), 2)
def test_self_message(self): self.request.post('/login/', {'username': self.provider.username, 'password': '******'}) sender = authenticate(username=self.provider.username, password='******') msg = Message(sender=sender, sender_site=None, subject="this was a triumph") recipient = sender msg.urgent = False msg.message_type = 'NM' msg.save() body = "i'm making a note here: huge success" msg_body = msg.save_body(body) MessageRecipient(message=msg, user=recipient).save() self.request.user = recipient test = CalledTest() models.sendSMS_Twilio_newMessage = test msg.send(self.request, msg_body, []) self.assertTrue(test.was_called) self.request.logout()
def handle_charge(invoice, charge, owner, **kwargs): # Notify the user via docotor com messaging, its account owner who gets message msg = Message(sender=None, sender_site=None, subject=_("Your Autopayment Processed")) recipient = MHLUser.objects.get(id=owner.id) msg.urgent = False msg.message_type = 'NM' msg.save() formatted_body = _("The payment in amount of $%s was charged to your credit card on file.") \ % (charge.amount) attachments = [] msg_body = msg.save_body(formatted_body) MessageRecipient(message=msg, user=recipient).save() # Send the message request = _FauxRequest() msg.send(request, msg_body, attachments)
def test_normal_message(self): self.request.post('/login/', {'username': self.provider.username, 'password': '******'}) sender = authenticate(username=self.provider.username, password='******') msg = Message(sender=sender, sender_site=None, subject="pandas") recipient = User.objects.get(id=self.provider2.id) msg.urgent = False msg.message_type = 'NM' self.assertRaises(Exception, msg.save_body, '') msg.save() body = "i am indeed a talking panda. how are you?" msg_body = msg.save_body(body) MessageRecipient(message=msg, user=recipient).save() test = CalledTest() models.sendSMS_Twilio_newMessage = test msg.send(self.request, msg_body, []) self.assertTrue(test.was_called) self.assertTrue(Message.objects.filter(sender=sender, subject="pandas").exists()) self.assertTrue(MessageRecipient.objects.filter(message=msg, user=recipient).exists()) msg_body.delete() clean_msg_body = MessageBody.objects.get(pk=msg_body.pk) self.request.logout() self.assertEqual(msg_body.decrypt(self.request), body) response = self.request.post('/login/', {'username': self.provider2.username, 'password': '******'}) self.request.user = authenticate(username=self.provider2.username, password='******') self.request.COOKIES = {'ss': response.cookies['ss'].value} try: self.assertEqual(clean_msg_body.decrypt(self.request), body) except KeyInvalidException: raise self.failureException("message body decryption failed") self.assertRaises(Exception, msg.save) self.assertRaises(Exception, msg.delete, self.request) self.assertRaises(Exception, msg.send, self.request, msg_body, []) self.request.logout()
def testGetMessage(self): sender = self.user msg = Message(sender=sender, sender_site=None, subject="pandas") msg.urgent = False msg.message_type = 'NM' msg.callback_number = '2561234561' msg.save() body = "i am indeed a talking panda. how are you?" msg_body = MessageBody(message=msg, body=body) msg_body.save() msgbus = MessageBodyUserStatus() msgbus.user = self.user msgbus.msg_body = msg_body msgbus.save() self.msgbus = msgbus self.object_type = ContentType.objects.get_for_model(msg_body) self.extra['HTTP_MDCOM_USER_UUID'] = self.user.uuid response = self.client.get(reverse( 'MHLogin.api.v1.views_messaging.getMessage', args=(msg.uuid,)), **self.extra) self.assertEqual(response.content, err_GE002().content, response.status_code)
def testMarkMessageRead(self): response = self.client.get(reverse( 'MHLogin.api.v1.views_messaging.markMessageRead'), **self.extra) self.assertEqual(response.content, err_GE002().content, response.status_code) self.user = create_user(get_random_username(), "mhluser", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "") self.user.mdcom_phone = '9002000001' self.user.save() sender = self.user msg = Message(sender=sender, sender_site=None, subject="pandas") msg.urgent = False msg.message_type = 'NM' msg.callback_number = '2561234561' msg.save() message_id = msg.uuid data = {'message_ids': [message_id]} response = self.client.post(reverse( 'MHLogin.api.v1.views_messaging.markMessageRead'), data, **self.extra) self.assertEqual(response.status_code, 200, response.status_code) msg = json.loads(response.content) self.assertEqual(len(msg), 2)
def test_invalid_recipient(self): self.request.post('/login/', { 'username': self.provider.username, 'password': '******' }) sender = authenticate(username=self.provider.username, password='******') msg = Message(sender=sender, sender_site=None, subject="this was a triumph") recipient = None msg.urgent = False msg.message_type = 'NM' msg.save() body = "i'm making a note here: huge success" msg_body = msg.save_body(body) self.assertRaises(ValueError, MessageRecipient, message=msg, user=recipient) self.assertRaises(InvalidRecipientException, msg.send, self.request, msg_body, []) self.request.logout()
def _convertVoicemails(output=sys.stderr): from models import VMMessage from django.db.models import Model vms = VMMessage.objects.all() for vm in vms: try: oldconfig = VMBox_Config.objects.get(owner_id=vm.owner_id) config = VMBox_Config.objects.get(owner_id=vm.owner_id) #url = vm.recording msg = Message(sender=None, sender_site=None, subject="Voice mail") msg.urgent = False msg.message_type = 'VM' msg.callback_number = vm.callbacknumber msg.read_flag = vm.read_flag msg.delete_flag = vm.deleted msg.save() MessageRecipient(message=msg, user=vm.owner).save() request = _FauxRequest() request.session['ivr_makeRecording_recording'] = vm.recording request.session[ 'ivr_makeRecording_callbacknumber'] = vm.callbacknumber attachment = save_voice_attachment(request, msg) msg_body = msg.save_body("Message from %s." % msg.callback_number) config.notification_page = False config.notification_sms = False config.save() msg.send(request, msg_body, [attachment]) msg.send_timestamp = time.mktime(vm.timestamp.timetuple()) Model.save(msg) oldconfig.save() except Exception as e: err_msg = "Warning no VMBoxConfig found for: %s, Exception: %s\n" \ % (repr(vm.owner), str(e)) output.write(err_msg) logger.warning(err_msg)
def test_self_message(self): self.request.post('/login/', { 'username': self.provider.username, 'password': '******' }) sender = authenticate(username=self.provider.username, password='******') msg = Message(sender=sender, sender_site=None, subject="this was a triumph") recipient = sender msg.urgent = False msg.message_type = 'NM' msg.save() body = "i'm making a note here: huge success" msg_body = msg.save_body(body) MessageRecipient(message=msg, user=recipient).save() self.request.user = recipient test = CalledTest() models.sendSMS_Twilio_newMessage = test msg.send(self.request, msg_body, []) self.assertTrue(test.was_called) self.request.logout()
def testRemoveProvider(self, start_thread): response = self.client.post(reverse('MHLogin.MHLOrganization.views_member.removeProvider'),\ data={'org_id': self.practice.id,'prov_id':1}) self.assertEqual(response.status_code, 404) sender = authenticate(username=self.user.username, password='******') msg = Message(sender=sender, sender_site=None, subject="pandas") recipient = User.objects.get(id=self.provider2.id) msg.urgent = False msg.message_type = 'NM' self.assertRaises(Exception, msg.save_body, '') msg.save() MessageRecipient(message=msg, user=recipient).save() response = self.client.post(reverse('MHLogin.MHLOrganization.views_member.removeProvider'),\ data={'org_id': self.practice.id,'prov_id':self.provider.id}) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(len(msg), 2) response = self.client.get(reverse('MHLogin.MHLOrganization.views_member.removeProvider'),\ data={'org_id': self.practice.id,'prov_id':self.provider.id}) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(len(msg), 2)
def testGetRefer(self): user = create_user('practicemgr', 'yang', 'peng', 'demo') msg = Message(sender=user, sender_site=None, subject="pandas") msg.urgent = False msg.callback_number = 2561234561 msg.save() refer = MessageRefer() refer.message = msg refer.gender = 'M' refer.status = 'AC' refer.phone_number = 8529631475 refer.alternative_phone_number = 1472583695 refer.home_phone_number = 8472583695 refer.save() refer_list = [refer] self.assertEqual(get_refer(refer_list), refer.status) with self.assertRaises(TypeError): get_refer(refer) #class Get_attachment_filenameTest(TestCase): # def test_get_attachment_filename(self): # user = create_user('practicemgr','yang','peng','demo') # msg = Message(sender=user, sender_site = None, subject="pandas") # msg.urgent = False # msg.callback_number = 2561234561 # msg.save() # request = generateHttpRequest() # msgCon = MessageContent() # msgCon.message=msg # msgCon.save() # attachment = MessageAttachment(msgCon) # attachment.size = '12' # attachment.save() # # _get_attachment_filename(request,msg)
def save_message(request, subject, recipients, cc=None, message_type='VM', urgent=False): #now that we live about 1.5ms away from twilio instead of 100ms, #we sometimes end up requesting recordings before twilio has put them up. #so we sleep for 100ms as a workaround time.sleep(.1) cc = cc or [] msg = Message(sender=None, sender_site=None, subject=subject) msg.urgent = urgent msg.message_type = message_type msg.callback_number = request.session['ivr_makeRecording_callbacknumber'] msg.save() attachments = [] all_recipients = recipients[:] for recipient in all_recipients: MessageRecipient(message=msg, user=recipient).save() if isinstance(cc, collections.Iterable): for recipient in cc: MessageCC(message=msg, user=recipient).save() if ('ivr_makeRecording_recording' in request.session): #make a file out of twilio recording attachment = save_voice_attachment(request, msg) if (attachment): attachments.append(attachment) #'For ANS ONLY! ivr_caller_id_area_code' present means the call back number contained no area code, #and we saved twillio's caller id are code if (message_type == 'ANS' and 'ivr_caller_id_area_code' in request.session): caller_id_area_code = " Area Code From Caller Id :%s." % \ request.session['ivr_caller_id_area_code'] else: caller_id_area_code = "" if ('ivr_only_callbacknumber' in request.session and request.session['ivr_only_callbacknumber']): if ('ivr_no_pound' in request.session and request.session['ivr_no_pound'] == True): formatted_body = _( "Caller hung up from CONFIRMED %s before leaving message. " "No attachment." ) % request.session['ivr_makeRecording_callbacknumber'] msg.vmstatus = 'C' else: formatted_body = _( "Caller hung up from unconfirmed %s before leaving message. " "No attachment." ) % request.session['ivr_makeRecording_callbacknumber'] msg.vmstatus = 'U' else: msg.vmstatus = 'R' if (attachments): formatted_body = "Message from %s.%s" % ( request.session['ivr_makeRecording_callbacknumber'], caller_id_area_code) else: # There was a recording, but Twilio must have errored when we # tried to get it. formatted_body = _("Message from %(callbacknumber)s. Unfortunately, an error occurred " "downloading the recording from our telephone company. We will " "automatically retry the download and you will receive a new " "message once the recording is successfully retrieved. This call " "will be referenced using the following ID: %(CallSid)s.\nWe " "apologize for any inconvenience.\nDoctorCom Staff") % \ {'callbacknumber': request.session['ivr_makeRecording_callbacknumber'], 'CallSid': request.REQUEST['CallSid']} url = request.session['ivr_makeRecording_recording'] log = AnsSvcDLFailure( practice_id=request.session.get('practice_id', 0), error_message_uuid=msg.uuid, recording_url=url, callback_number=request. session['ivr_makeRecording_callbacknumber'], failure_type='DL', ) log.init_from_post_data(request.REQUEST) log.save() msg_body = msg.save_body(formatted_body) event = callEvent(callSID=request.POST['CallSid'], event='V_NMG') target = callEventTarget(event=event, target=msg) # Send the message msg.send(request, msg_body, attachments)
def handle_errors(invoice, charge, owner, **kwargs): if not charge: # The user does not have a CC# number attached and charge never went through # logging.error(" %s does not have credit card entered", owner) # Notify the user via docotor com messaging, its account owner who gets message msg = Message( sender=None, sender_site=None, subject="Action required: Please set up Doctor Com Billing") recipient = MHLUser.objects.get(id=owner.id) msg.urgent = False msg.message_type = 'NM' msg.save() formatted_body = "The last charge for your last invoice in the amount of $%s was " \ "rejected due to the missing billing information of file. Please update your " \ "billing information. Contact [email protected], if you have any additional " \ "questions." % (invoice.accounttransaction.amount) attachments = [] msg_body = msg.save_body(formatted_body) MessageRecipient(message=msg, user=recipient).save() # Send the message request = _FauxRequest() msg.send(request, msg_body, attachments) # email support email_body = "Account number %s failed autopayment due to account owner not " \ "having a payment instrument on file." % (invoice.accounttransaction.account.id) email_msg = EmailMessage("Problem with payment", email_body, settings.DEFAULT_FROM_EMAIL, settings.SUPPORT_RECIPIENTS) email_msg.send() else: # logging.error(" %s error charging with message. %s", (owner, charge.message)) # Notify the user via docotor com messaging, its account owner who gets message msg = Message(sender=None, sender_site=None, subject="Action required: " "Your last auto payment was rejected") recipient = MHLUser.objects.get(id=owner.id) msg.urgent = False msg.message_type = 'NM' msg.save() formatted_body = _( "The last charge for your last invoice in the amount of " "$%(amount)s was rejected with the following error: %(message)s Please update " "your billing information. Contact [email protected] if you have any additional " "questions.") % { 'amount': charge.amount, 'message': charge.message } attachments = [] msg_body = msg.save_body(formatted_body) MessageRecipient(message=msg, user=recipient).save() # Send the message request = _FauxRequest() msg.send(request, msg_body, attachments) # email support email_body = "Account number %(account_id)s failed autopayment due to the " \ "following error %(message)s" % {'account_id': invoice.accounttransaction.account.id, 'message': charge.message} email_msg = EmailMessage("Problem with payment", email_body, settings.DEFAULT_FROM_EMAIL, settings.SUPPORT_RECIPIENTS) email_msg.send()