---
updatedAt: 2025-07-15T08:37:26.000Z
agentTools:
  projectIndex: https://docs.appery.io/llms.txt
---

# Ionic Mailgun Email Sample App

Sending email from an Ionic app with Mailgun ​API

​This example uses [Mailgun](https://www.mailgun.com/) API to send emails from an Ionic app.

This sample app uses and demonstrates:

* Ionic.
* [Appery.io](https://appery.io) **[Server Code](https://appery.io/servercode/)**.
* Invoking an external REST API.

> 🚧 Important Note!
>
> Our Mailgun Email Sample App contains ready to use services and the UI that makes it easy to use.\
> Note that you will need to add your actual [Mailgun Account](https://docs.appery.io/docs/ionic-5-mailgun-email-sample-app-with-server-code-plugin#mailgun-account) to make it work.

# Getting App Backend

## Mailgun Account

To send emails with the **[Mailgun](https://docs.appery.io/docs/servercode-plugins)** plugin, you will need to create a [Mailgun Account](http://mailgun.com/) and get a domain, API Key ID and SMTP credentials that will be later used in the [Server Code script](https://docs.appery.io/docs/ionic-5-mailgun-email-sample-app-with-server-code-plugin#configuring-server-code-script) of our sample app.

* To get your Mailgun *domain*, open the [**Sending > Domains**](https://app.mailgun.com/app/sending/domains) page:

<Image align="center" className="border" border={true} src="https://files.readme.io/b402ed3-Screenshot_46.png" />

* To get your Mailgun *Private API Key ID*, open the [**Settings > API security**](https://app.mailgun.com/app/account/security/api_keys) page:

<Image align="center" className="border" border={true} src="https://files.readme.io/5d3cdf3-Screenshot_10.png" />

* You will also need to specify your username and it can be found/modified under [**Sending > Domain settings > SMTP credentials**](https://app.mailgun.com/app/sending/domains/sandboxe7bbfa4a213848d099d909124bcc6cbf.mailgun.org/credentials) page of your Mailgun active domain (optional):

<Image align="center" className="border" border={true} src="https://files.readme.io/fcceb95-Screenshot_16.png" />

## Importing *MailgunEmail* plugin

1. Go to the **[Server Code](https://appery.io/servercode/)** page.
2. Open the **[Plugins](https://docs.appery.io/docs/servercode-overview#plugins)** tab.
3. Import the **MailgunEmail** plugin:

<Image align="center" className="border" border={true} src="https://files.readme.io/daa9287-Screenshot_2.png" />

4. Click the  imported script to open it and set up your ***Mailgun domain*** (line 8), ***api key*** (line 12), and ***from*** (line10) parameters and save your work:

<Image align="center" className="border" border={true} src="https://files.readme.io/6d54131-Screenshot_20.png" />

### Testing Script

It is a good idea to test your script now.

To do it, you can replace the default script values **to**, **subject** and **body** in the script or open the **[Script Parameters](https://docs.appery.io/docs/servercode-script#script-parameters)** tab, select ***JSON*** for **Request body**, and provide the needed values there, for example, `{"to": "test@example.com", "subject":"Appery.io test", "body":"Hello World!"}`:

<Image align="center" className="border" border={true} src="https://files.readme.io/7efddb2-Screenshot_19.png" />

Finally, switch from the **[Script Parameters](https://docs.appery.io/docs/servercode-script#script-parameters)** tab to the **[Run](https://docs.appery.io/docs/servercode-script#run-testing)** tab and click the **Save and run** button.

> 🚧 Note
>
> Please be informed that with a free Mailgun plan, you will be able to send messages to [authorized recipients](https://help.mailgun.com/hc/en-us/articles/217531258) only:

<Image align="center" className="border" border={true} src="https://files.readme.io/510862e-Screenshot_12.png" />

If your authorized recipient user checks the inbox now, the email will be there (if it is not, please check the **Spam** folder):

<Image align="center" className="border" width="smart" border={true} src="https://files.readme.io/9a04cb6-Screenshot_22.png" />

Now, let's proceed with creating an app..

# Creating App

> 👍 NEW: One-Click Template Installation!
>
> You can now enjoy the one-click-away option of installing the template app: simply click the button below and in a moment, your app is ready to start! There’s no need to go to the **Create new app** dialog or download the template backup with further installing it.

<HTMLBlock>{`
<html><head><style>
    .btn:link,
    .btn:visited {
        text-decoration: none;
        padding: 15px 40px;
        display: inline-block;
        border-radius: 100px;
        transition: all .2s;
        position: relative;
        color: #fff;
    }

    .btn:hover {
        transform: translateY(-3px);
        box-shadow: 0 10px 20px rgba(0, 0, 0, .2);
    }

    .btn:active {
        transform: translateY(-1px);
        box-shadow: 0 5px 10px rgba(0, 0, 0, .2);
    }

    .btn-green {
        background-color: #09B300;
        color: #fff;
    }

    .btn::after {
        content: "";
        display: inline-block;
        height: 100%;
        width: 100%;
        border-radius: 100px;
        position: absolute;
        top: 0;
        left: 0;
        z-index: -1;
        transition: all .4s;
    }

    .btn-green::after {
        background-color: #55c57a;
    }

    .btn:hover::after {
        transform: scaleX(1.4) scaleY(1.6);
        opacity: 0;
    }
</style>

</head><body><a href="https://appery.io/app/projects/action/create-from-template?name=MailgunEmailApp&guid=f813b41f-418a-412b-b011-a4b302a16ee5" class="btn btn-green" target="_blank" >Create in Appery.io</a></body></html>
`}</HTMLBlock>

You can also create this app by using our **Create new app** dialog like described in the sections below.&#x9;

> 🚧 Important!
>
> Note that if you decide to follow the one-click template installation procedure, you will need to provide the value for the service URL **servercode\_id** parameter under the **Request > Query String** tab:

<Image align="center" className="border" border={true} src="https://files.readme.io/34db5f2-Screenshot_25.png" />

> 👍 Server Code Script Service URL
>
> To locate the Server Code Script Service URL, go to the **[Server Code](https://appery.io/servercode)** tab, select the needed script from the drop-down **Scripts** list on the left, then switch to the script **[API information tab](https://docs.appery.io/docs/servercode-script#rest-api-information)**:

<Image align="center" className="border" width="smart" border={true} src="https://files.readme.io/a48fb47-Screenshot_23.png" />

Once done with this, your app is ready to go and you can skip the sections below proceed with [testing](https://docs.appery.io/docs/ionic-5-mailgun-email-sample-app-with-server-code-plugin#app-testing) the app in preview.

However, if you are interested in the details, please follow the instructions on creating the app from scratch below.

## Creating App UI

1. From the **Apps** page, click **Create new app > Ionic Blank**.
2. Name it ***MailgunEmail App*** and confirm.
3. After the **[App Builder](https://docs.appery.io/docs/apperyio-app-builder-overview)** loads, open **Pages >[Screen1](https://docs.appery.io/docs/screens-and-tabs#pages-screens)** in the **[Project](https://docs.appery.io/docs/apperyio-visual-builder#project-view)** view tree, select **[Toolbar Title](https://docs.appery.io/docs/ionic-5-ui-components-properties#toolbar-title)** of the screen **[Header](https://docs.appery.io/docs/screens-and-tabs#header-and-footer)** and change its **Text** property to ***MailgunEmail App***.
4. Also, drag the **[Button](https://docs.appery.io/docs/ionic-5-ui-components-properties#button)** and drop it to the **Header > Toolbar >[Toolbar Buttons](https://docs.appery.io/docs/ionic-5-ui-components-properties#toolbar-buttons)** component.
5. To add the icon for the added button **Custom SVG Icon** property, click the **Change** button next to it to open the **[Media Manager](https://docs.appery.io/docs/3-creating-an-app-ui-styling-apps#using-media-manager)** for uploading and then applying the needed image file:

<Image align="center" className="border" border={true} src="https://files.readme.io/fd321a4-Screenshot_27.png" />

> 👍
>
> Note, that to be able to preview the listed images, you need to pre-upload them to the app by using the **[Media Manager](https://docs.appery.io/docs/3-creating-an-app-ui-styling-apps#using-media-manager)**. To open it, click the **Additional Menu** (the three lines button) in the upper-right corner of the **[App Builder Toolbar](https://docs.appery.io/docs/apperyio-app-builder-overview#toolbar)** and select **Media Manager**; then upload the needed images.\
> When ready, the uploaded files will become available under the **[Source Tab](https://docs.appery.io/docs/apperyio-app-builder-overview#source-tab)**:

6. Clear the button **Text** property value:

<Image align="center" className="border" border={true} src="https://files.readme.io/d5c399f-2023-03-27_12-32-48.png" />

7. For this app, you will need two **[Input](https://docs.appery.io/docs/ionic-5-ui-components-properties#input)**, one **[Textarea](https://docs.appery.io/docs/ionic-5-ui-components-properties#textarea)**, and one **[Button](https://docs.appery.io/docs/ionic-5-ui-components-properties#button)** components.\
   So, drag the first **[Input](https://docs.appery.io/docs/ionic-5-ui-components-properties#input)** from **[PALETTE](https://docs.appery.io/docs/1-creating-an-app-ui-palette#ui-components-palette-overview)** to the **[Content](https://docs.appery.io/docs/2-creating-an-app-ui-pages-and-tabs#content-component)** area of the **[Screen1](https://docs.appery.io/docs/screens-and-tabs#pages-screens)** page and modify its properties as follows:

* **Comp. Name** = ***ToInput***;
* **Input Mode** = ***Email***;
* **Type** = ***Email***;
* **Label > Text** = ***To:***

<Image align="center" className="border" border={true} src="https://files.readme.io/7d54536-2023-03-27_12-34-43.png" />

7. Now, drag another **[Input](https://docs.appery.io/docs/ionic-5-ui-components-properties#input)** and drop it to **[Screen1](https://docs.appery.io/docs/screens-and-tabs#pages-screens)** and set its properties as follows:

* **Comp. Name** = ***SubjectInput***;
* **Label > Text** = ***Subject:***:

<Image align="center" className="border" border={true} src="https://files.readme.io/3768a19-2023-03-27_12-36-12.png" />

8. Next, drag the **[TextArea](https://docs.appery.io/docs/ionic-5-ui-components-properties#textarea)** component and drop it to the screen; then set up its properties as follows:

* **Comp. Name** = ***MessageTextarea***;
* **Label > Text** = ***Message:***:

<Image align="center" className="border" border={true} src="https://files.readme.io/a322fd4-2023-03-27_12-37-22.png" />

9. Finally, add the **[Button](https://docs.appery.io/docs/ionic-5-ui-components-properties#button)** component to the page and define it like this:

* **Comp. Name** = ***SendEmailButton***;
* **Text** = ***Send Email***;\
  Now, click the **Icon > Style** default icon (***No icon***) to open the icon selection window and select the needed icon. in our sample app, ***paper-plane*** is selected:

<Image align="center" className="border" border={true} src="https://files.readme.io/59d6947-2023-03-27_12-39-28.png" />

The app UI is ready and should look like this:

<Image align="center" className="border" width="smart" border={true} src="https://files.readme.io/be48dec-2023-03-27_12-40-36.png" />

## Configuring Server Code Script

Now, you need to configure the needed **[Server Code script](https://docs.appery.io/docs/servercode-script)**.

1. So let's first add the [imported](https://docs.appery.io/docs/ionic-5-mailgun-email-sample-app-with-server-code-plugin#importing-mailgunemail-plugin) Server Code script to the app.\
   Click **Create New > Server Code Service**, select **MailgunEmailExample** script, and confirm the operation to import the selected service to the app:

<Image align="center" className="border" width="smart" border={true} src="https://files.readme.io/f9b4443-Screenshot_38.png" />

2. The service will be instantly imported into the **Services** folder inside the **App Builder** **[Project view](https://docs.appery.io/docs/apperyio-visual-builder#project-view)** tree.\
   Click the imported service and set its **Request Content Type** parameter to ***JSON***:

<Image align="center" className="border" border={true} src="https://files.readme.io/c230123-Screenshot_39.png" />

3. Then open the **Request > Body** tab, click the **Import** button, and import the next request structure:

```typescript Request Service Parameters Import
{"to": "test@example.com", "subject":"Appery.io test", "body":"Hello World!"}
```

<Image align="center" className="border" border={true} src="https://files.readme.io/5bcf396-Screenshot_41.png" />

Here is how the **Body Request** tab should look like:

<Image align="center" className="border" border={true} src="https://files.readme.io/c2f5050-Screenshot_42.png" />

That's all you need to do to configure this script.

## Defining App Logic

1. Go to the **Screen 1[DATA](https://docs.appery.io/docs/apperyio-visual-builder#data-panel)** panel and add a datasource for the **MailgunEmailExample** service; name it to ***sendEmail***:

<Image align="center" className="border" border={true} src="https://files.readme.io/cd96604-Screenshot_40.png" />

2. Click the **Before send** service mapping button to open the mapping editor and map the following properties to the corresponding body request parameters:\
   ***ToInput > Value*** = ***to***;\
   ***SubjectInput > Value*** = ***subject***;\
   ***MessageTextarea >Value*** = ***body***.
3. Click **Save & Replace** to save your work:

<Image align="center" className="border" border={true} src="https://files.readme.io/4394b45-Screenshot_43.png" />

4. To add the alert notifying that the message has been sent successfully, click the arrow button next to the service **Success** event, select the **[Present alert](https://docs.appery.io/docs/ionic-4-events-and-actions#present-alert)** action from the list, and define message text as ***Email has been sent!***. Save the action:

<Image align="center" className="border" border={true} src="https://files.readme.io/e70666c-Screenshot_44.png" />

5. The last thing is to invoke the service that you have set up:\
   Go back to the page **[DESIGN](https://docs.appery.io/docs/apperyio-visual-builder#design-panel)** panel, select the ***SendEmail Button*** and for its **[Click](https://docs.appery.io/docs/5-event-handling#common-events)** event, select the **[Invoke service](https://docs.appery.io/docs/ionic-4-events-and-actions#invoke-service)** action defined with the ***sendEmail*** service:

<Image align="center" className="border" border={true} src="https://files.readme.io/dea59f5-2023-03-27_12-42-37.png" />

# App Testing

You are now ready to test your app on preview: click the **TEST** button in the **[App Builder Toolbar](https://docs.appery.io/docs/apperyio-app-builder-overview#toolbar)** to run the app in the preview to launch the app in the browser.\
Now, enter the addressee, subject, message and click the **Send Email** button:

<Image align="center" className="border" width="smart" border={true} src="https://files.readme.io/4b2bff1-2023-03-27_12-45-32.png" />

You are also free to publish the app web version or export bundles to install it on the device.