Giter Site home page Giter Site logo

dsanghan / mailer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kaisellgren/mailer

0.0 1.0 0.0 235 KB

Compose and send emails from Dart. Supports file attachments, HTML emails and multiple transport methods.

License: MIT License

Dart 100.00%

mailer's Introduction

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.

TODO HELP WANTED

  • 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 = '[email protected]';
  String password = 'password';

  final smtpServer = gmail(username, password);
  // Use the SmtpServer class to configure an SMTP server:
  // final smtpServer = SmtpServer('smtp.domain.com');
  // See the named arguments of SmtpServer for further configuration
  // options.  
  
  // Create our message.
  final message = Message()
    ..from = Address(username, 'Your name')
    ..recipients.add('[email protected]')
    ..ccRecipients.addAll(['[email protected]', '[email protected]'])
    ..bccRecipients.add(Address('[email protected]'))
    ..subject = 'Test Dart Mailer library :: ๐Ÿ˜€ :: ${DateTime.now()}'
    ..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('[email protected]')`
  // If you want to display a name part you have to create an
  // Address object: `new Address('[email protected]', 'Display name part')`
  // Creating and adding an Address object without a name part
  // `new Address('[email protected]')` is equivalent to
  // adding the mail address as `String`.
  final equivalentMessage = Message()
      ..from = Address(username, 'Your name')
      ..recipients.add(Address('[email protected]'))
      ..ccRecipients.addAll([Address('[email protected]'), '[email protected]'])
      ..bccRecipients.add('[email protected]')
      ..subject = 'Test Dart Mailer library :: ๐Ÿ˜€ :: ${DateTime.now()}'
      ..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.

mailer's People

Contributors

analogic avatar bajajerk avatar butlermatt avatar close2 avatar henrichen avatar jbaxe2 avatar jodinathan avatar kaisellgren avatar pjkroll avatar selkhateeb avatar tomyeh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.