Email messaging between users

Hi, I’ve been building a feature for a client and am not sure I’m on the right track.

The feature provides the functionality for users to send each other messages via email without their personal email being revealed.

the project is using mailgun and has email set as the USERNAME_FIELD

for context, userA can message userB, with userB receiving an email from: postmaster@mg.mydomain.

When userB replies, mailgun forwards the email to a view to handle parsing and to then send the response to userA, where userA receives email from: postmaster@…

What I am struggling with is the identification of the userA on the reply to allow the send function to use the correct email address.

I could change the initial send to be firstName_lastName@mg.mydomain but this doesn’t help for multiple users with the same name. I’m trying to avoid adding a uid onto the name.

I’m currently working on using a hidden tag in the body with a uuid associated for the sender and receiver

sender_uuid = request.user.profile.email_uuid
recipient_uuid = recipient.profile.email_uuid
  
# Create context with UUIDs for email body template
context = {
    'sender_uuid': sender_uuid,
    'recipient_uuid': recipient_uuid,
    'message': message,
}

# Load email body template
email_body_template = Template("""
            <html>
            <body>
                <p>Your message: {{ message }}</p>
                <input type="hidden" name="sender_uuid" value="{{ sender_uuid }}">
                <input type="hidden" name="recipient_uuid" value="{{ recipient_uuid }}">
                <p>If you need to reply, please use the reply feature in your email client.</p>
            </body>
            </html>
        """)

# Render email body template with context
email_body = email_body_template.render(Context(context))

# Send email
email = EmailMultiAlternatives(
        f'Message from {request.user.username}',
        message,  # Text content
        sender_email,  # From email
        [recipient_email],  # To email
    )
email.attach_alternative(email_body, "text/html")  # Attach HTML content
email.send()

I wanted to check if I was on the right track here or have I missed a much simpler way to solve this?

Thanks
Brendon