enough_mail_html 2.0.1 copy "enough_mail_html: ^2.0.1" to clipboard
enough_mail_html: ^2.0.1 copied to clipboard

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

example/enough_mail_html_example.dart

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) =>
    mimeMessage.transformToHtml();

String generatePlainText(String htmlText) =>
    HtmlToPlainTextConverter.convert(htmlText);

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

Future<String> playYourself(MimeMessage mimeMessage) async {
  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'];
    }
  }
}
4
likes
160
pub points
80%
popularity

Publisher

verified publisherenough.de

Generate HTML from an email mime message and creates plain text from HTML. 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