---
title: "Sending Emails with Mailgun"
description: "How to use Mailgun to send emails with LaunchFast starter kits?"
source: "https://www.launchfa.st/documentation/emails/mailgun"
---

> **Site index for agents**
> Fetch https://www.launchfa.st/llms.txt to discover every page on this site.
> Every page is also available as Markdown by appending `.md` to its URL.

> Browse the source code [here](https://github.com/LaunchFast-Boilerplates/launchfa.st-astro/blob/master/src/lib/utils/email.ts).

import { Steps, Tabs, TabItem } from '@astrojs/starlight/components'

LaunchFa.st makes it easier for you to send emails with [Mailgun](https://mailgun.com) with it's built-in integration.

Here's how you would set up Mailgun to use it with LaunchFast:

<Steps>
  1. Create a [Mailgun](https://mailgun.com) account.
  2. Add and verify your domain(s) by completing the steps in their [domain guide](https://help.mailgun.com/hc/en-us/articles/32884702360603-Domain-Verification-Setup-Guide).
  3. Obtain the Mailgun API key as per their [API Key Instructions](https://help.mailgun.com/hc/en-us/articles/203380100-Where-can-I-find-my-API-keys-and-SMTP-credentials).
  4. Make sure to update the environment variable(s) of your application per the following instruction:
    
      <Tabs>
        <TabItem label="Astro">
            [https://github.com/LaunchFast-Boilerplates/launchfa.st-astro#email](https://github.com/LaunchFast-Boilerplates/launchfa.st-astro#email)
        </TabItem>
        <TabItem label="SvelteKit">
            [https://github.com/LaunchFast-Boilerplates/launchfa.st-sveltekit#email](https://github.com/LaunchFast-Boilerplates/launchfa.st-sveltekit#email)
        </TabItem>
        <TabItem label="Next.js">
            [https://github.com/LaunchFast-Boilerplates/launchfa.st-nextjs#email](https://github.com/LaunchFast-Boilerplates/launchfa.st-nextjs#email)
        </TabItem>
      </Tabs>
</Steps>

To send emails with Mailgun, use `sendEmail` utility inside your server-side code:

<Tabs>

<TabItem label="Astro">

```typescript
// File: src/pages/api/random.ts

import { sendEmail } from '@/lib/utils/email'
import type { APIContext } from 'astro'

export async function GET({ request }: APIContext) {
  // From a server-side API that is being fetched

  // Send an email using Resend
  // Read more on https://resend.com/docs/api-reference/emails/send-email
  await sendEmail({
    text: context.text,
    subject: context.subject,
    from: 'Rishi Raj Jain <emails@rishi.app>',
    to: typeof context.to === 'string' ? [context.to] : context.to,
  }, 'mailgun')
}

export async function POST({ request }: APIContext) {
  // From a server-side API that is being POST-ed to

  // Send an email using Resend
  // Read more on https://resend.com/docs/api-reference/emails/send-email
  await sendEmail({
    text: context.text,
    subject: context.subject,
    from: 'Rishi Raj Jain <emails@rishi.app>',
    to: typeof context.to === 'string' ? [context.to] : context.to,
  }, 'mailgun')
}
```

</TabItem>

</Tabs>
