Dart is a great programming language from Google that is widely used in cross platform app development. In this post we'll show you how to send and receive emails within Dart code. This can be used in apps to send login emails or in tests to test user sign-up or notifications.

Install Dart

First thing we need to install Dart. On a mac we can use brew like so:

Configure a project

Create a new directory and add a to describe the project and dependencies:

Create a simple test

Next we can write a simple test to demonstrate email sending. Let's call it .

Inside the test file import the and packages.

Setup email client

Next we can use the mailslurp package to configure email sending and receiving. It's free for personal use but requires an API Key.

Then add a setup function:

Next add configuration for MailSlurp:

Creating email addresses

Disposable email mailboxes are a common need during testing. We can create an inbox using MailSlurp like this:

Send emails in dart

To send emails use the inbox controller with an inbox ID:

Receive and read emails

To download emails we can use an instance of the to wait for an expected email in a given inbox:

Next steps

Dart has many other email abilities. To find out more see the MailSlurp documentation.