mailer 3.0.4

  • Readme
  • Changelog
  • Installing
  • 96

mailer #

mailer is an easy to use library for composing and sending emails in Dart.

Mailer supports file attachments and HTML emails.

mailer2 and mailer3 #

mailer2 and mailer3 on pub.dart are forks of this project.

mailer was not well maintained and mailer2 and mailer3 had some important fixes.

Currently mailer should include all known bug-fixes and AFAIK there is no reason to use mailer2 or mailer3.

Dart2 support #

Support for dart2 has been added in version ^1.2.0

Version ^2.0.0 is a rewrite (it too supports dart1.x and dart2).

Even though the API for ^2.0.0 has slightly changed, most programs will probably continue to work with deprecation warnings.

SMTP definitions #

Mailer provides configurations for a few common SMTP servers.

Please create merge requests for missing configurations.

  • Copy lib/smtp_server/gmail.dart to lib/smtp_server/xxx.dart
  • Adapt the code. (See lib/smtp_server.dart for possible arguments)
  • Export the newly created SMTP server in lib/smtp_server.dart
  • Create a pull request.

In a lot of cases you will find a configuration in legacy.dart

Features #

  • Plaintext and HTML emails
  • Unicode support
  • Attachments
  • Secure (filters and sanitizes all fields context-wise)
  • Use any SMTP server like Gmail, Live, SendGrid, Amazon SES
  • SSL/TLS support
  • Pre-configured services (Gmail, Yahoo, Hotmail, etc.). Just fill in your username and password.


  • Correct encoding of non ASCII mail addresses.
  • Reintegrate address validation from version 1.*
  • Improve Header types. (see ir_header.dart)
    We should choose the correct header based on the header name.
    Known headers (list-unsubscribe,...) should have their own subclass.
  • Improve documentation.

Examples #

Sending an email with SMTP #

See gmail example.

import 'package:mailer/mailer.dart';
import 'package:mailer/smtp_server.dart';

main() async {
  String username = '';
  String password = 'password';

  final smtpServer = gmail(username, password);
  // Use the SmtpServer class to configure an SMTP server:
  // final smtpServer = SmtpServer('');
  // See the named arguments of SmtpServer for further configuration
  // options.  
  // Create our message.
  final message = Message()
    ..from = Address(username, 'Your name')
    ..ccRecipients.addAll(['', ''])
    ..subject = 'Test Dart Mailer library :: 😀 :: ${}'
    ..text = 'This is the plain text.\nThis is line 2 of the text part.'
    ..html = "<h1>Test</h1>\n<p>Hey! Here's some HTML content</p>";

  try {
    final sendReport = await send(message, smtpServer);
    print('Message sent: ' + sendReport.toString());
  } on MailerException catch (e) {
    print('Message not sent.');
    for (var p in e.problems) {
      print('Problem: ${p.code}: ${p.msg}');
  // DONE
  // Let's send another message using a slightly different syntax:
  // Addresses without a name part can be set directly.
  // For instance `..recipients.add('')`
  // If you want to display a name part you have to create an
  // Address object: `new Address('', 'Display name part')`
  // Creating and adding an Address object without a name part
  // `new Address('')` is equivalent to
  // adding the mail address as `String`.
  final equivalentMessage = Message()
      ..from = Address(username, 'Your name')
      ..ccRecipients.addAll([Address(''), ''])
      ..subject = 'Test Dart Mailer library :: 😀 :: ${}'
      ..text = 'This is the plain text.\nThis is line 2 of the text part.'
      ..html = "<h1>Test</h1>\n<p>Hey! Here's some HTML content</p>";
  final sendReport2 = await send(equivalentMessage, smtpServer);
  // Sending multiple messages with the same connection
  // Create a smtp client that will persist the connection
  var connection = PersistentConnection(smtpServer);
  // Send the first message
  await connection.send(message);
  // send the equivalent message
  await connection.send(equivalentMessage);
  // close the connection
  await connection.close();

License #

This library is licensed under MIT.

3.0.4 #

  • fix null pointer when server doesn't support EHLO (#121)

3.0.3 #

  • fix splitting of text for base64 conversion.

3.0.2 #

3.0.1 #

  • allow older pedantic version to make mailer compatible with flutter.

3.0.0 #

  • NO BUGFIXES. There is no need to update!
  • remove dart 1 compatible code. mailer does require dart 2.2.2 or higer now.
  • remove catchExceptions flag. mailer now always throws.
  • change return value of send from List<SendReport> to SendReport
  • add persistent connection (idea from
  • add xoauth2 authentication method (see examples)

2.5.1 #

  • assign catchExceptions if null

2.5.0 #

  • export exceptions.

2.4.0 #

  • add catchExceptions flag to send command. (issue #90)

2.3.0 #

  • add timeout option. (
  • add catchExceptions flag (currently true, but default will change to false) improve exceptions.
  • remove username from authentication failure exception (see issue #79)

2.2.1 #

  • fix regular expression which is used to validate the name of an email address.

2.2.0 #

  • add qq smtp server definition

2.1.2 #

  • improve exception when server response does not match.

2.1.1 #

  • if a header value is null send empty string instead.
  • if mime library fails to identify content use text/plain and application/octet-stream
    as defaults.
  • mention mailer2 and mailer3 in README

2.1.0 #

  • provide smtp_servers in smtp_server.dart

2.0.2 #

  • added smtp configuration for

>1.1.4 <2.0.2 #

Please see README and commits.

1.1.4 #

  • Remove extra trailing \r\n from messages as some servers may interpret it as an empty command and send back an error code after success code

1.1.3 #

  • Fix occasional issue with completer already completed. Due to an error with SMTP server closing connection after sending the email.

1.1.2 #

  • Fix new lines sent to server to be proper \r\n format

1.1.1 #

  • loosen crypto dependency to '>=0.9.0 <3.0.0' as suggested in the crypto changelog

1.1.0 #

  • merge crypto util fix and update example
  • upgrade unittest to test and move it to dev_dependencies
  • added OpenMailBoxSmtpOptions
  • improve address parsing and sanitization (from hoylen)
  • cleanup chunkEncodedBytes and associated test
  • update example to allow CC and BCC

1.0.1 #

  • add simple example/
  • fix pubspec to pull crypto 0.9.0

1.0.0 - Oct 4, 2015 #

  • initial release

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  mailer: ^3.0.4

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:mailer/mailer.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Mar 26, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Fix lib/src/smtp/smtp_client.dart. (-3.93 points)

Analysis of lib/src/smtp/smtp_client.dart reported 8 hints, including:

line 21 col 22: Unnecessary new keyword.

line 57 col 20: Unnecessary new keyword.

line 63 col 11: Unnecessary new keyword.

line 84 col 11: Unnecessary new keyword.

line 105 col 11: Unnecessary new keyword.

Fix lib/src/smtp/mail_sender.dart. (-1 points)

Analysis of lib/src/smtp/mail_sender.dart reported 2 hints:

line 12 col 24: Unnecessary new keyword.

line 23 col 35: Unnecessary new keyword.

Fix lib/src/smtp/internal_representation/ir_header.dart. (-0.50 points)

Analysis of lib/src/smtp/internal_representation/ir_header.dart reported 1 hint:

line 122 col 20: Avoid const keyword.

Fix lib/src/utils.dart. (-0.50 points)

Analysis of lib/src/utils.dart reported 1 hint:

line 5 col 27: Unnecessary new keyword.

Maintenance suggestions

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and mailer.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.2 <3.0.0
async >=2.0.0 <3.0.0 2.4.1
intl >0.9.0 <1.0.0 0.16.1
logging >0.0.1 <1.0.0 0.11.4
mime >0.9.0 <1.0.0 0.9.6+3
path >0.9.0 <2.0.0 1.6.4
pedantic >=1.5.0 <2.0.0 1.9.0
Transitive dependencies
collection 1.14.12
Dev dependencies
args >=1.5.0 <2.0.0
googleapis_auth ^0.2.7
test >=1.5.1 <2.0.0