Anonymized email relaying is very useful for creating a safe space for users to contact privately. This integration can often be done in just a couple of hours.
Popular online marketplaces such as Craigslist, Airbnb, and many others, as well as many online communities, need to allow their market participants to communicate with each other without sharing their private data. Elastic Email provides a simple out of the box integration. It enables anonymized email relaying functionality via our Inbound Email API. Note, this article is a technical article aimed at software developers. Some basic programming is required to receive and process posts from our API.
Table of contents
Use an example of the anonymous, two-way email communication
How to set anonymized email relaying up using Elastic Email
- Setup DNS MX Record:
- Create a Webhook Endpoint:
- Start the conversation by using the Elastic Email outbound API
- Receiving the reply via the Webhook:
- Elastic Email does the rest
Storing messages in an inbox (Optional)
Anonymized email relaying - easy to implement and widely needed feature
Use an example of the anonymous, two-way email communication
Let’s say you’re creating a new online marketplace. For example, a classified site called bikesforu.com where people can post their bicycles for sale. Members of this site sign up, take a picture and post their bikes online. Our example seller signs up with his email address from gmail.com
Meanwhile, buyers browse the site looking for their perfect bike. When they find it, they want to send an email to the seller. The site wants to support this communication between participants but the participants' private email addresses should not be shared.
When the buyer submits an email to the seller they, the seller, should receive the email from an anonymous branded address like:
buyer4338@mail.bikesforu.com
We want to allow them to reply to this email directly from their email inbox. When they do, the email should be sent directly to the buyer's actual email address from:
seller9383@mail.bikesforu.com
The two can then have a “normal” email exchange between them without actually sharing their true personal email addresses.
Optionally, the site should have the ability to monitor or sensor this communication and store the conversation in a thread on bikesforu.com. By having this, the two participants could come back and review the conversation later. Airbnb does this, Craigslist does not.
How to set anonymized email relaying up using Elastic Email
Elastic Email makes setting up this two-way anonymous communication fast and easy using our inbound email API and a smart webhook.
1. Setup DNS MX Record:
In order to set up anonymized email relaying we first, must set up the mail received by our domain to arrive at Elastic Email’s inbound SMTP API. Our example company has its actual email addresses at bikesforu.com. We can use a subdomain at mail.bikesforu.com to facilitate our buyer and sellers' email.
New MX record: MX mail.bikesforu.com points to mx.inbound.elasticemail.com
Once this is set up, then any email sent to anyaddress@mail.bikesforu.com will arrive at the Elastic Email inbound SMTP API and will be parsed.
In addition to the MX record, you should also set up email security DNS records for SPF and DKIM for mail.bikesforu.com.
Make sure that all records are set up correctly by doing a DNS lookup. SPF, DKIM, and MX records are quite sensitive in nature and dramatically affect email deliverability. So, it is always a good idea to double check them.
2. Create a Webhook Endpoint:
Setup an HTTP webhook URL on your web server which can access the sellers and buyers who are in your app's database. For our example, we will set up a new webhook endpoint at:
https://app.bikesforu.com/inboundemail
Once we have this URL we can add this to the inbound setup in our Elastic Email account. This completes the basic setup at Elastic Email. Now, any email sent to anyaddress@mail.bikesforu.com will be received by our SMTP API, parsed using our powerful MIME parsers and split into handy chunks of data which will be sent via HTTP POST to your web server.
3. Start the conversation by using the Elastic Email outbound API
Let’s say the buyer has just requested more information from the seller on one of the bikes. They entered their email in the app, wrote their message and hit send.
When this happens bikesforu.com stores the email address of the buyer as a new “buyer” account and assigns the buyer a unique ID.
They then send an email to the sellers' real email address containing the buyers' message via the standard Elastic Email outbound API: https://api.elasticemail.com/public/help#Email_Send
The critical step is to build the FROM email address of the message using the buyers' unique ID - for example:
buyer4338@mail.bikesforu.com
Thanks to this, the seller will receive the email. At the same time, the buyer is protected from sharing their information.
4. Receiving the reply via the Webhook:
When the seller replies to the email from their email software the message will be sent to the buyer's address @ mail.bikesforu.com. We set up the MX server for that to go to Elastic Email’s inbound SMTP API. So it will be parsed and sent via HTTP to our webhook.
When Elastic Email posts the inbound mail to your webhook, it will include quite a lot of data. For the sake of this example, we will focus on several specific fields:
from_email (from address)
to_list (list of email addresses the email was sent to, separated by commas)
subject (email subject)
body_html (HTML body content)
body_html_reply (new content in the email only - this excludes historical thread information)
Each of these fields from the received email will be standard HTTP Post parameters.
When https://app.bikesforu.com/inboundemail receives this POST it must resolve the from_email and the to_list to the appropriate members on the site. Then, it can respond to the web request with instructions for Elastic Email on what to do with the email.
The web response needs to look like this for Elastic Email to understand it:
{ relay_to: “buyers real email address”, from_email: “seller9383@mail.bikesforu.com” }
So the webhook must take the to_list of email addresses which in our example will be just one email address: buyer4338@mail.bikesforu.com - parse out the unique buyer ID and look up in the database the real email address for the buyer.
It must also take the seller's real email address which is passed in via the from_email parameter. Look up the seller's account to get their unique ID and build a private email address for them. In this case seller9382@mail.bikesforu.com. These two values go back to Elastic Email in the response format above as the response to the webhook call.
5. Elastic Email does the rest
At this point, we’ve instructed Elastic Email to anonymous email relay and resolved the private email addresses to use in the conversation. Elastic Email will now construct and submit a new outbound email back to the buyer using the seller's bikesforu.com email address. The buyer can reply and the conversation can continue just like any normal email communication thread.
Storing messages in an inbox(Optional)
If bikesforu.com wanted to capture the conversation going on between the buyer and the seller and store it in an inbox in the app they can use the body_html_reply parameter to capture just the reply content added in each email (without the additional re: thread content that usually exists in email) and store this in their database so the participants could review the conversation later in the app.
Anonymized email relaying - easy to implement and widely needed feature
Using Elastic Email with a single webhook API call and a few DNS settings, we can set up a powerful, private and anonymous two-way email communication system between market or community participants. Enjoy!
As always the Elastic Email support team is here to help if you have any questions getting your anonymized email relaying integration setup.