def save_msg(request, to_user, auth_code):

    authmsg = create_authmsg(request, to_user, auth_code)

    aeskeyp1, aeskeyp2, cphr_authmsg = cncrypto.aes_encrypt_authcode(authmsg)
    cphr_aeskeyp1 = cncrypto.rsa_encrypt_aeskey(to_user.pubkey, aeskeyp1)

    msg = Message()
    msg.from_org = request.user.get_profile().organization
    msg.to_user = to_user
    msg.sysid = str(uuid.uuid4())
    msg.enc_msg = cphr_authmsg
    msg.save()

    key = Key()
    key.message = msg
    key.sysid = str(uuid.uuid4())
    key.key = cphr_aeskeyp1
    key.min_to_expire = 1
    key.save()

    from_email = "%s <*****@*****.**>" % (
        request.user.get_profile().organization.name)
    subject = "Authorization request"
    body = """
<a href="secdef://%s/%s">Tap Here</a> to get your authentication code.
""" % (msg.sysid, urllib.quote_plus(base64.b64encode(aeskeyp2)))

    print body

    email_msg = EmailMessage(subject, body, from_email, [to_user.email])
    email_msg.content_subtype = "html"
    email_msg.send()