Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mailslurp/mailslurp-client-dart
Dart Flutter Client for MailSlurp Email API
https://github.com/mailslurp/mailslurp-client-dart
Last synced: 2 months ago
JSON representation
Dart Flutter Client for MailSlurp Email API
- Host: GitHub
- URL: https://github.com/mailslurp/mailslurp-client-dart
- Owner: mailslurp
- License: mit
- Created: 2020-11-10T17:00:04.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-06-03T06:05:42.000Z (8 months ago)
- Last Synced: 2024-06-03T07:31:51.316Z (8 months ago)
- Language: Dart
- Size: 3.05 MB
- Stars: 4
- Watchers: 1
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Security: SECURITY.md
- Support: SUPPORT.md
Awesome Lists containing this project
README
# Dart MailSlurp package
MailSlurp is a free API for creating email accounts. Send and receive emails from Dart and Flutter code and tests.
## Quick links
- [Pub.dev package](https://pub.dev/packages/mailslurp)
- [GitHub source](https://github.com/mailslurp/mailslurp-client-dart)
- [Get API Key](https://app.mailslurp.com/sign-up/)
- [Documentation](https://docs.mailslurp.com/dart/doc/)## Install
```bash
dart pub add mailslurp
```## Configure
First configure the default api client with your MailSlurp API Key:
```dart
import 'package:mailslurp/api.dart';defaultApiClient.getAuthentication('API_KEY').apiKey = 'YOUR_MAILSLURP_API_KEY';
```## Use controllers
The MailSlurp Dart library exports controllers that map to the [REST API](https://api.mailslurp.com/swagger-ui.html). Controller methods return Futures that can be consumed in async methods.
```dart
var inboxController = InboxControllerApi();// future result
Future inbox = inboxController.createInboxWithOptions(CreateInboxDto());// or async usage
void main() async {
var inbox = await inboxController.createInboxWithOptions(CreateInboxDto());
}
```## Create email addresses
You can create real email accounts using the InboxController:
```dart
test('can create email addresses', () async {
var inboxController = InboxControllerApi();
var inbox = await inboxController.createInboxWithOptions(CreateInboxDto());
expect(inbox.emailAddress.contains("@mailslurp"), true);
});
```## Send emails
Send emails using the InboxController with an `inboxId`:
```dart
test('can send emails', () async {
var inboxController = InboxControllerApi();
var inbox = await inboxController.createInboxWithOptions(CreateInboxDto());var confirmation = await inboxController.sendEmailAndConfirm(inbox.id,
sendEmailOptions: SendEmailOptions(
to: [inbox.emailAddress],
subject: "Test email",
body: "My message",
isHTML: true
)
);
expect(confirmation.inboxId, inbox.id);
});
```## Receive emails
Receive emails using the WaitForController with an `inboxId` and a timeout.
```dart
test('can receive emails', () async {
var email = await waitForController.waitForLatestEmail(inboxId: inbox.id, timeout: 30000, unreadOnly: true);
expect(email.subject, "Test email");
});
```## Test usage
```dart
import 'dart:io';import 'package:test/test.dart';
import 'package:mailslurp/api.dart';void main() async {
setUp(() {
// read api key from environment variable
var apiKey = Platform.environment["API_KEY"];
expect(apiKey != null, true);// set api key and instantiate controllers
defaultApiClient.getAuthentication('API_KEY').apiKey = apiKey;
});test('can create email addresses', () async {
var inboxController = InboxControllerApi();
var inbox = await inboxController.createInboxWithOptions(CreateInboxDto());
expect(inbox.emailAddress.contains("@mailslurp"), true);
});test('can send and receive emails', () async {
var inboxController = InboxControllerApi();
var waitForController = WaitForControllerApi();var inbox = await inboxController.createInboxWithOptions(CreateInboxDto());
var confirmation = await inboxController.sendEmailAndConfirm(inbox.id,
sendEmailOptions: SendEmailOptions(
to: [inbox.emailAddress],
subject: "Test email",
body: "My message",
isHTML: true
)
);
expect(confirmation.inboxId, inbox.id);var email = await waitForController.waitForLatestEmail(inboxId: inbox.id, timeout: 30000, unreadOnly: true);
expect(email.subject, "Test email");
});
}
```