mailer2 1.2.5

Mailer #

Note: this is a temporary fork of Kai Sellgren's Mailer ( for aggressive support of Reply-To and List-Unsubscribe

Who Uses #

  • Quire - a simple, collaborative, multi-level task management tool.

Introduction #

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

Mailer supports file attachments, HTML emails and multiple transport methods.

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, Live,, etc.). Just fill in your username and password.

Filing bug tickets #

Please call printDebugInformation() from the mailer package and send the output along with your helpful explanation of what went wrong.


  • All possible SMTP authentication methods (now just LOGIN)
  • Sendmail
  • Stream attachments
  • String-based attachments

Examples #

Sending an email with SMTP #

In this example we send an email using a Gmail account.

import 'package:mailer/mailer.dart';

main() {
  // If you want to use an arbitrary SMTP server, go with `new SmtpOptions()`.
  // This class below is just for convenience. There are more similar classes available.
  var options = new GmailSmtpOptions()
    ..username = 'your gmail username'
    ..password = 'your gmail password'; // Note: if you have Google's "app specific passwords" enabled,
                                        // you need to use one of those here.
  // How you use and store passwords is up to you. Beware of storing passwords in plain.

  // Create our email transport.
  var emailTransport = new SmtpTransport(options);

  // Create our mail/envelope.
  var envelope = new Envelope()
    ..from = ''
    ..subject = 'Testing the Dart Mailer library'
    ..attachments.add(new Attachment(file: new File('path/to/file')))
    ..text = 'This is a cool email message. Whats up?'
    ..html = '<h1>Test</h1><p>Hey!</p>';

  // Email it.
    .then((envelope) => print('Email sent!'))
    .catchError((e) => print('Error occurred: $e'));

License #

This library is licensed under MIT.

1.2.5 #

  • Allow local-part to start with a dot

1.2.4 #

  • Allow local-part to end with a dot

1.1.6 #

  • Introduce listUnsubscribe
  • Remove replyTo and replyToName

1.1.5 #

  • Updated for Dart 2, including updating dependency versions.

1.1.5 #

  • Introduce replyTos
  • Deprecate replyTo and replyToName

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:

  mailer2: ^1.2.5

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:mailer2/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 Feb 13, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5

Health suggestions

Fix lib/src/address.dart. (-25 points)

Analysis of lib/src/address.dart reported 58 hints, including:

line 127 col 13: Unnecessary new keyword.

line 130 col 13: Unnecessary new keyword.

line 146 col 13: Unnecessary new keyword.

line 149 col 13: Unnecessary new keyword.

line 154 col 15: Unnecessary new keyword.

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

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

line 5 col 1: Prefer using /// for doc comments.

line 11 col 3: Prefer using /// for doc comments.

line 20 col 3: Prefer using /// for doc comments.

line 25 col 3: Prefer using /// for doc comments.

line 29 col 49: Unnecessary new keyword.

Fix lib/src/envelope.dart. (-4.41 points)

Analysis of lib/src/envelope.dart reported 9 hints, including:

line 3 col 1: Prefer using /// for doc comments.

line 30 col 3: Prefer using /// for doc comments.

line 36 col 18: Unnecessary new keyword.

line 39 col 7: DO use curly braces for all flow control structures.

line 79 col 7: DO use curly braces for all flow control structures.

Fix additional 5 files with analysis or formatting issues. (-4.49 points)

Additional issues in the following files:

  • lib/src/util.dart (4 hints)
  • lib/src/attachment.dart (2 hints)
  • lib/mailer.dart (1 hint)
  • lib/src/sendmail_transport.dart (1 hint)
  • lib/src/smtp/smtp_transport.dart (1 hint)

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 mailer2.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.0.0-dev <3.0.0
charcode >=1.1.2 <2.0.0 1.1.3
dart2_constant ^1.0.0 1.0.2+dart2
intl >0.9.0 <2.0.0 0.16.1
logging >=0.11.3+2 <2.0.0 0.11.4
mime >0.9.0 <2.0.0 0.9.6+3
path >0.9.0 <2.0.0 1.6.4
Dev dependencies
args >0.13.0 <2.0.0
test >0.12.0 <2.0.0