dart_mailgun 1.0.0 copy "dart_mailgun: ^1.0.0" to clipboard
dart_mailgun: ^1.0.0 copied to clipboard

A Dart package for interfacing with the Mailgun API

Unit Tests

dart-mailgun #

Mailgun API client written in dart

Forked from dotronglong's repo as it had been unmaintaned for a while.

This is still heavily in development so do keep that in mind. I'll publish the package on pub as soon as I've properly tested it. If you want to add it to your project you'll therefore have to import it from github as shown below.

Getting Started #

  • Add dependency
dependencies:
  flutter_mailgun:
    git: https://github.com/beccauwu/flutter-mailgun.git
  • Initialise client instance
import 'package:dart_mailgun/client.dart';


var client = MailgunClient(domain: "my-mailgun-domain", apiKey: "my-mailgun-api-key");
  • Initialise client with eu host
import 'package:dart_mailgun/client.dart';


var client = MailgunClient.eu(domain: "my-mailgun-domain", apiKey: "my-mailgun-api-key");
  • Send plain text email
var messageClient = client.message
var params = MessageParams(
  from: from,
  to: to,
  subject: 'email',
  content: MessageContent.text('hello'),
  )
)
  • Send HTML email
var messageClient = client.message
var params = MessageParams(
  from: from,
  to: to,
  subject: 'email',
  content: MessageContent.html('<h1>hello</h1>'),
  )
  • Send email using template and template variables
var messageClient = client.message
var params = MessageParams(
  from: from,
  to: to,
  subject: 'email',
  content: MessageContent.template('mytemplate', {'var1': 'val1'}),
  )
  • Send email with attachments
var messageClient = client.message
var params = MessageParams(
  from: from,
  to: to,
  subject: 'email',
  content: MessageContent.text('hello'),
  attachments: [File('myfile.txt')],

Response #

Responses from any clients will be an instance of the Response class.

The response contains two methods: ok(), and status(). ok() returns a boolean indicating a successful response, status() returns an instance of ResponseStatus, which contains the statuscode status().code and reasonphrase status().reason.

The body is found in response.body and will parse both text responses and json responses. In the case of text, the response is found under body['message'].

var response = await client.send(params)
if(!response.ok()){
  //handle error
  print(response.status().reason)
} else {
  var body = await response.body
  print(body['message'])
  // handle result
}
3
likes
0
pub points
73%
popularity

Publisher

verified publisherperttula.xyz

A Dart package for interfacing with the Mailgun API

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

http, intl

More

Packages that depend on dart_mailgun