Last updated:
0 purchases
mailslurp
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
GitHub source
Get API Key
Documentation
Install #
dart pub add mailslurp
copied to clipboard
Configure #
First configure the default api client with your MailSlurp API Key:
import 'package:mailslurp/api.dart';
defaultApiClient.getAuthentication<ApiKeyAuth>('API_KEY').apiKey = 'YOUR_MAILSLURP_API_KEY';
copied to clipboard
Use controllers #
The MailSlurp Dart library exports controllers that map to the REST API. Controller methods return Futures that can be consumed in async methods.
var inboxController = InboxControllerApi();
// future result
Future<Inbox> inbox = inboxController.createInboxWithOptions(CreateInboxDto());
// or async usage
void main() async {
var inbox = await inboxController.createInboxWithOptions(CreateInboxDto());
}
copied to clipboard
Create email addresses #
You can create real email accounts using the InboxController:
test('can create email addresses', () async {
var inboxController = InboxControllerApi();
var inbox = await inboxController.createInboxWithOptions(CreateInboxDto());
expect(inbox.emailAddress.contains("@mailslurp"), true);
});
copied to clipboard
Send emails #
Send emails using the InboxController with an inboxId:
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: "<html>My message</html>",
isHTML: true
)
);
expect(confirmation.inboxId, inbox.id);
});
copied to clipboard
Receive emails #
Receive emails using the WaitForController with an inboxId and a timeout.
test('can receive emails', () async {
var email = await waitForController.waitForLatestEmail(inboxId: inbox.id, timeout: 30000, unreadOnly: true);
expect(email.subject, "Test email");
});
copied to clipboard
Test usage #
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<ApiKeyAuth>('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: "<html>My message</html>",
isHTML: true
)
);
expect(confirmation.inboxId, inbox.id);
var email = await waitForController.waitForLatestEmail(inboxId: inbox.id, timeout: 30000, unreadOnly: true);
expect(email.subject, "Test email");
});
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.