enough_mail_html 1.1.0
enough_mail_html: ^1.1.0 copied to clipboard

Generate HTML from an email mime message. Eases handling of `MimeMessage` in the `enough_mail` package.

Generate html code from any email mime message for displaying it.

Usage #

The enough_mail_html package defines the decodeTextHtmlForDisplay() extension method on MimeMessage of the enough_mail package.

This method will always generate HTML, specifically also for plain text or empty messages. You can define your custom processors

  • for converting a plain text message into HTML,
  • for adapting the HTML message,
  • for handling inline attachments.

A simple usage example:

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

String generateHtml(MimeMessage mimeMessage) {
  return mimeMessage.transformToHtml(
        blockExternalImages: false, emptyMessageText: 'Nothing here, move on!');
}

More examples:

import 'package:enough_mail/enough_mail.dart';
import 'package:enough_mail_html/enough_mail_html.dart';
import 'package:html/dom.dart';

String simpleTransformExample(MimeMessage mimeMessage) {
  return mimeMessage.transformToHtml();
}

String configureImageBlockingOrEmptyMessage(MimeMessage mimeMessage) {
  return mimeMessage.transformToHtml(
      blockExternalImages: true, emptyMessageText: 'Nothing here, move on!');
}

String playYourself(MimeMessage mimeMessage) {
  final cfg = TransformConfiguration.create(
      blockExternalImages: true,
      emptyMessageText: 'Nothing here, move on!',
      customDomTransformers: [StyleTextDomTransformer()],
      customValues: {'textStyle': 'font-size:10px;font-family:verdana;'});
  return mimeMessage.transformToHtml(transformConfiguration: cfg);
}

class StyleTextDomTransformer extends DomTransformer {
  @override
  void process(Document document, MimeMessage message,
      TransformConfiguration configuration) {
    final paragraphs = document.getElementsByTagName('p');
    for (final paragraph in paragraphs) {
      paragraph.attributes['style'] = configuration.customValues['textStyle'];
    }
  }
}

Installation #

Add this dependency your pubspec.yaml file:

dependencies:
  enough_mail_html: ^1.0.0

The latest version or enough_mail_html is enough_mail_html version.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

License #

Licensed under the commercial friendly Mozilla Public License 2.0.

2
likes
120
pub points
62%
popularity

Publisher

enough.de

Generate HTML from an email mime message. Eases handling of `MimeMessage` in the `enough_mail` package.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MPL 2.0 (LICENSE)

Dependencies

enough_mail, html, image

More

Packages that depend on enough_mail_html