enough_mail 0.0.36 copy "enough_mail: ^0.0.36" to clipboard
enough_mail: ^0.0.36 copied to clipboard

outdated

IMAP, POP3 and SMTP email clients in pure Dart. Choose between a low level and a high level API for mailing.

Experimental IMAP, POP3 and SMTP clients for Dart developers.

Available under the commercial friendly MPL Mozilla Public License 2.0.

Warning: Incoming Changes to v0.0.x API #

I will change the API to use exceptions rather than Response objects, before increasing the version of this package to 0.1.0. This will ease the usage in the happy sunshine cases drastically. Also compare https://github.com/Enough-Software/enough_mail/issues/101. Thanks for testing enough_mail!

High Level API Usage #

A simple usage example for using the high level API:

import 'dart:io';
import 'package:enough_mail/enough_mail.dart';

String userName = 'user.name';
String password = 'password';

void main() async {
  await mailExample();
}

Future<void> mailExample() async {
  var email = userName + '@domain.com';
  var config = await Discover.discover(email);
  var account =
      MailAccount.fromDiscoveredSetings('my account', email, password, config);
  var mailClient = MailClient(account, isLogEnabled: true);
  await mailClient.connect();
  var mailboxesResponse =
      await mailClient.listMailboxesAsTree(createIntermediate: false);
  if (mailboxesResponse.isOkStatus) {
    print(mailboxesResponse.result);
    await mailClient.selectInbox();
    var fetchResponse = await mailClient.fetchMessages(count: 20);
    if (fetchResponse.isOkStatus) {
      for (var msg in fetchResponse.result) {
        printMessage(msg);
      }
    }
  }
  mailClient.eventBus.on<MailLoadEvent>().listen((event) {
    print('New message at ${DateTime.now()}:');
    printMessage(event.message);
  });
  mailClient.startPolling();
}

Low Level Usage #

A simple usage example for using the low level API:

import 'dart:io';
import 'package:enough_mail/enough_mail.dart';

String userName = 'user.name';
String password = 'password';
String imapServerHost = 'imap.domain.com';
int imapServerPort = 993;
bool isImapServerSecure = true;
String popServerHost = 'pop.domain.com';
int popServerPort = 995;
bool isPopServerSecure = true;
String smtpServerHost = 'smtp.domain.com';
int smtpServerPort = 465;
bool isSmtpServerSecure = true;

void main() async {
  await discoverExample();
  await imapExample();
  await smtpExample();
  await popExample();
  exit(0);
}

Future<void> discoverExample() async {
  var email = 'someone@enough.de';
  var config = await Discover.discover(email, isLogEnabled: false);
  if (config == null) {
    print('Unable to discover settings for $email');
  } else {
    print('Settings for $email:');
    for (var provider in config.emailProviders) {
      print('provider: ${provider.displayName}');
      print('provider-domains: ${provider.domains}');
      print('documentation-url: ${provider.documentationUrl}');
      print('Incoming:');
      print(provider.preferredIncomingServer);
      print('Outgoing:');
      print(provider.preferredOutgoingServer);
    }
  }
}

Future<void> imapExample() async {
  var client = ImapClient(isLogEnabled: false);
  await client.connectToServer(imapServerHost, imapServerPort,
      isSecure: isImapServerSecure);
  var loginResponse = await client.login(userName, password);
  if (loginResponse.isOkStatus) {
    var listResponse = await client.listMailboxes();
    if (listResponse.isOkStatus) {
      print('mailboxes: ${listResponse.result}');
    }
    var inboxResponse = await client.selectInbox();
    if (inboxResponse.isOkStatus) {
      // fetch 10 most recent messages:
      var fetchResponse = await client.fetchRecentMessages(
          messageCount: 10, criteria: 'BODY.PEEK[]');
      if (fetchResponse.isOkStatus) {
        var messages = fetchResponse.result.messages;
        for (var message in messages) {
          printMessage(message);
        }
      }
    }
    await client.logout();
  }
}

Future<void> smtpExample() async {
  var client = SmtpClient('enough.de', isLogEnabled: true);
  await client.connectToServer(smtpServerHost, smtpServerPort,
      isSecure: isSmtpServerSecure);
  var ehloResponse = await client.ehlo();
  if (!ehloResponse.isOkStatus) {
    print('SMTP: unable to say helo/ehlo: ${ehloResponse.message}');
    return;
  }
  var loginResponse = await client.login('user.name', 'password');
  if (loginResponse.isOkStatus) {
    var builder = MessageBuilder.prepareMultipartAlternativeMessage();
    builder.from = [MailAddress('My name', 'sender@domain.com')];
    builder.to = [MailAddress('Your name', 'recipient@domain.com')];
    builder.subject = 'My first message';
    builder.addTextPlain('hello world.');
    builder.addTextHtml('<p>hello <b>world</b></p>');
    var mimeMessage = builder.buildMimeMessage();
    var sendResponse = await client.sendMessage(mimeMessage);
    print('message sent: ${sendResponse.isOkStatus}');
  }
}

Future<void> popExample() async {
  var client = PopClient(isLogEnabled: false);
  await client.connectToServer(popServerHost, popServerPort,
      isSecure: isPopServerSecure);
  var loginResponse = await client.login(userName, password);
  //var loginResponse = await client.loginWithApop(userName, password); // optional different login mechanism
  if (loginResponse.isOkStatus) {
    var statusResponse = await client.status();
    if (statusResponse.isOkStatus) {
      print(
          'status: messages count=${statusResponse.result.numberOfMessages}, messages size=${statusResponse.result.totalSizeInBytes}');
      var listResponse =
          await client.list(statusResponse.result.numberOfMessages);
      print(
          'last message: id=${listResponse.result?.first?.id} size=${listResponse.result?.first?.sizeInBytes}');
      var retrieveResponse =
          await client.retrieve(statusResponse.result.numberOfMessages);
      if (retrieveResponse.isOkStatus) {
        printMessage(retrieveResponse.result);
      } else {
        print('last message could not be retrieved');
      }
      retrieveResponse =
          await client.retrieve(statusResponse.result.numberOfMessages + 1);
      print(
          'trying to retrieve newer message succeeded: ${retrieveResponse.isOkStatus}');
    }
  }
  await client.quit();
}

void printMessage(MimeMessage message) {
  print('from: ${message.from} with subject "${message.decodeSubject()}"');
  if (!message.isTextPlainMessage()) {
    print(' content-type: ${message.mediaType}');
  } else {
    var plainText = message.decodeTextPlainPart();
    if (plainText != null) {
      var lines = plainText.split('\r\n');
      for (var line in lines) {
        if (line.startsWith('>')) {
          // break when quoted text starts
          break;
        }
        print(line);
      }
    }
  }
}

Installation #

Add this dependency your pubspec.yaml file:

dependencies:
  enough_mail: ^0.0.36

The latest version or enough_mail is enough_mail version.

Check out these related projects:

Miss a feature or found a bug? #

Please file feature requests and bugs at the issue tracker.

Contribute #

Want to contribute? Please check out contribute. This is an open-source community project. Anyone, even beginners, can contribute.

This is how you contribute:

  • Fork the enough_mail project by pressing the fork button.
  • Clone your fork to your computer: git clone github.com/$your_username/enough_mail
  • Do your changes. When you are done, commit changes with git add -A and git commit.
  • Push changes to your personal repository: git push origin
  • Go to enough_mail and create a pull request.

Thank you in advance!

Features #

Done #

The following IMAP extensions are supported:

Supported encodings #

Character encodings:

  • ASCII (7bit)
  • UTF-8 (uft8, 8bit)
  • ISO-8859-1 (latin-1)
  • ISO-8859-2 - 16 (latin-2 - 16)
  • Windows-1250, 1251, 1252

Transfer encodings:

To do #

Develop and Contribute #

  • To start check out the package and then run pub run test to run all tests.
  • Public facing library classes are in lib, lib/imap and lib/smtp.
  • Private classes are in lib/src.
  • Test cases are in test.
  • Please file a pull request for each improvement/fix that you are create - your contributions are welcome.
  • Check out https://github.com/enough-Software/enough_mail/contribute for good first issues.

License #

enough_mail is licensed under the commecial friendly Mozilla Public License 2.0.

117
likes
0
pub points
91%
popularity

Publisher

verified publisherenough.de

IMAP, POP3 and SMTP email clients in pure Dart. Choose between a low level and a high level API for mailing.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

basic_utils, crypto, enough_convert, enough_serialization, event_bus, http, intl, pedantic, xml

More

Packages that depend on enough_mail