enough_mail 0.0.16 enough_mail: ^0.0.16 copied to clipboard
IMAP and SMTP clients in pure Dart. Strives to be compliant with IMAP4 rev1, IMAP IDLE, IMAP METADATA Extension and SMTP.
An experimental IMAP and SMTP client for Dart developers.
Available under the commercial friendly MPL Mozilla Public License 2.0.
Usage #
A simple usage example:
import 'dart:io';
import 'package:enough_mail/enough_mail.dart';
void main() async {
await imapExample();
await smtpExample();
exit(0);
}
Future<void> imapExample() async {
var client = ImapClient(isLogEnabled: false);
await client.connectToServer('imap.domain.com', 993, isSecure: true);
var loginResponse = await client.login('user.name', '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) {
for (var message in fetchResponse.result) {
print(
'from: ${message.from} with subject "${message.decodeSubject()}"');
if (!message.isPlainTextMessage()) {
print(' content-type: ${message.mediaType}');
} else {
var plainText = message.decodePlainTextPart();
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);
}
}
}
}
}
}
await client.logout();
}
}
Future<void> smtpExample() async {
var client = SmtpClient('enough.de', isLogEnabled: false);
await client.connectToServer('smtp.domain.com', 465, isSecure: true);
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.addPlainText('hello world.');
builder.addHtmlText('<p>hello <b>world</b></p>');
var mimeMessage = builder.buildMimeMessage();
var sendResponse = await client.sendMessage(mimeMessage);
print('message sent: ${sendResponse.isFailedStatus}');
}
}
Installation #
Add this dependency your pubspec.yaml file:
dependencies:
enough_mail: ^0.0.16
The latest version or enough_mail
is .
Features and bugs #
Please file feature requests and bugs at the issue tracker.
Want to contribute? Please check out contribute.
Done #
- ✅ basic IMAP4 rev1 support
- ✅ IMAP IDLE support
- ✅ IMAP METADATA support
- ✅ basic SMTP support
- ✅ MIME parsing and generation support
Supported encodings #
Character encodings:
- ASCII (7bit)
- UTF-8 (uft8, 8bit)
- ISO-8859-1 (latin-1)
Transfer encodings:
To do #
- Compare issues
- hardening & bugfixing
- support more encodings
- improve performance
- support IMAP4 rev1 fully
- support QRESYNC and CONDSTORE
- support UIDPLUS
- support Message Preview Generation
- support WebPush IMAP Extension
- support Open PGP
- support POP3
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.