Email Configuration
Set up reliable email services for your SaaS using Mailgun.
Introduction
Every SaaS application needs reliable email functionality for notifications and transactional emails. ZapStart integrates seamlessly with Mailgun, which offers excellent deliverability with affordable pricing options.
While we recommend Mailgun for its reliability and pricing, ZapStart can work with any SMTP provider. The instructions below are specific to Mailgun setup.
The UI of the Mailgun may change, but the options will almost always remain the same.
Setting Up Mailgun
Creating Your Account
Sign up for a new account at Mailgun.com
During signup, you'll be asked to choose a plan. You can start with a trial of their Foundation plan
Complete the verification process (Mailgun requires phone verification)
Domain Setup
- In your Mailgun dashboard, navigate to Sending → Domains
- Click Add New Domain and enter your domain
For better email management and deliverability, we highly recommend using a subdomain (e.g.,
mail.yourdomain.com
ormg.yourdomain.com
) instead of your root domain. - Choose your region (US or EU)
If you select EU region, you'll need to update your Mailgun client configuration with the European API endpoint. Just Uncomment the
url: "https://api.eu.mailgun.net/"
line in the backend/src/libs/mailgun.js file. - Click Create Domain
DNS Verification
After creating your domain, Mailgun will provide DNS records that need to be added to your domain's DNS settings:
- Add all the required TXT, MX, and CNAME records to your DNS provider
- For enhanced deliverability, add an additional DMARC record:
Record Type: TXT
Name: _dmarc.mail.yourdomain.com
Value: v=DMARC1; p=none
- Wait for DNS propagation, it takes from seconds to few minutes to take effect.
- Check the verification status in your Mailgun dashboard
DNS verification is crucial for email deliverability. Make sure all records are properly configured before proceeding.
API Keys
API Keys
- Go to Domain Settings → Sending Keys → Add Sending Key and give a description to the key.
- Copy the key to
MAILGUN_API_KEY
variable in your .env file.
Receiving Emails
To receive emails at addresses like support@mail.yourdomain.com
, you'll need to set up email forwarding with Mailgun routes:
Setting Up Routes for Email Forwarding
- In your Mailgun dashboard, navigate to Receiving → Create Route
- Set up the route with:
- Expression Type: Match Recipient
- Recipient:
support@mail.yourdomain.com
make sure to use the same domain and subdomain you choose in the domain setup - Forward to:
your-personal-email@gmail.com
, you could also add your backend server endpoint to handle the emails, e.g.https://your-backend-server.com/api/webhook/email
, sometimes this could be useful to handle the emails in a more sophisticated way, like sending it to the right person to reply to the customer. Follow the Advanced section below for more details.
- Click Create Route
Advanced: Handling Email Replies (Optional)
For a complete customer communication system, you can set up webhook forwarding:
- Create an API route in your application to handle incoming emails
- In Mailgun, go to the same route we just created and at Forward to, add your backend server endpoint, e.g.
https://your-backend-server.com/api/webhook/email
besides your personal email (the email that you choose asforwardRepliesTo
in theconfigBack.js
file) (separated by a comma). - Configure the webhook signing key for security:
- Go to Sending → Webhooks
- Copy the HTTP webhook signing key
- Add it to your .env.local as
MAILGUN_SIGNING_KEY
and use it in your email webhook code to verify the request.
With webhook forwarding, you can build sophisticated features like email-based customer support, comment systems, or automated response handling, but this is not necessary for the basic email functionality and you could just use your personal email. Your main goal is to launch your Startup (MVP) fast.
Application Configuration
Update your mailgun object configuration in backend/configBack.js
and frontend/configFront.js
files. You'll find instructions inside the files.
The configuration above allows you to customize all email-related settings in one place, making it easy to update them as needed.
Email Workflow Recap
How Email Works with ZapStart
Sending Emails
Your application sends emails (notifications, purchase success, etc.) from your configured domain (e.g., team@mail.yourdomain.com
). These emails have excellent deliverability because they're authenticated with your domain's DNS records.
Receiving Emails
When customers email your support address (e.g., support@mail.yourdomain.com
):
- Mailgun receives the email
- Your configured route forwards it to your personal email (and optionally your webhook)
- You respond from your personal email
This creates a seamless experience for your customers while allowing you to manage support communications from your regular email client.
Best Practice for Support
Create a dedicated personal email address specifically for handling customer inquiries (e.g., help.yourname@gmail.com
). This keeps your support communications separate from your personal or business email and makes it easier to manage customer interactions.
For a tutorial on how to send emails, please see the Email Tutorial.
Next Steps
Now that you've configured your JWT secrets, MongoDB, Google OAuth and Email, you can continue setting up the rest:
- Integrate payment processing
- Fill in the Config files with the correct values
Always test your email setup in a development environment before deploying to production. Mailgun provides detailed logs to help troubleshoot delivery issues. Also make sure to finish the verification process in Mailgun.