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

  1. Sign up for a new account at Mailgun.com

  2. During signup, you'll be asked to choose a plan. You can start with a trial of their Foundation plan

  3. Complete the verification process (Mailgun requires phone verification)

Domain Setup

  1. In your Mailgun dashboard, navigate to SendingDomains
  2. 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 or mg.yourdomain.com) instead of your root domain.

  3. 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.

  4. 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:

  1. Add all the required TXT, MX, and CNAME records to your DNS provider
  2. For enhanced deliverability, add an additional DMARC record:

    Record Type: TXT

    Name: _dmarc.mail.yourdomain.com

    Value: v=DMARC1; p=none

  3. Wait for DNS propagation, it takes from seconds to few minutes to take effect.
  4. 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

  1. Go to Domain SettingsSending KeysAdd Sending Key and give a description to the key.
  2. 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

  1. In your Mailgun dashboard, navigate to ReceivingCreate Route
  2. 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.
  3. Click Create Route

Advanced: Handling Email Replies (Optional)

For a complete customer communication system, you can set up webhook forwarding:

  1. Create an API route in your application to handle incoming emails
  2. 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 as forwardRepliesTo in the configBack.js file) (separated by a comma).
  3. Configure the webhook signing key for security:
    • Go to SendingWebhooks
    • 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):

  1. Mailgun receives the email
  2. Your configured route forwards it to your personal email (and optionally your webhook)
  3. 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:

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.