Forwarding Texts to Email
This guide will show you how to write a webhook to handle incoming text messages to a SignalWire phone number and forward them to an email address.
We will write a simple server that listens for a message event from SignalWire when an SMS is received, then uses Mailgun.js to send an email.
What You Need to Run This Code
- You can find the full code for this application on GitHub.
- You will need a Mailgun API key and Domain.
- You will need your SignalWire credentials (i.e., Space URL, Project ID, and API token). If you need help finding these, please see Navigating your SignalWire Space.
- You will also need to visit your SignalWire Space to set up your SignalWire phone number message handler.
Configuring the phone number
First, we need to create a new Relay Application resource. To do so, go to the "Resources" section from your sidebar, and create a new Relay ApplicationResource.

When configuring the Relay Application, set the topic to "office" (to match what we have in the code).
If you don't have a phone number yet, make sure to buy one. You will need at least one number to receive messages.
You can do that from the "Phone Numbers" section in the Sidebar. Go to the Settings page of the number you
want to configure. In the Inbound Message Settings
section, assign your relay application.

Feel free to use the email delivery service of your choice. Our example will use Mailgun, but this implementation works just as well with other services. Just check their documentation for how to call their API.
How to Run the Application
Build and Run on Docker
Start by building the image with docker build -t smstoemail .
Then run the container with the command docker run -it --rm -p 3000:3000 --name smstoemail --env-file .env smstoemail
.
Build and Run Natively
If you would like to run it natively, clone the GitHub repo and run it with npm start
in your terminal.