Sample code for 30+ languages & platforms
Dart

Send HTML Email with Image Downloaded from URL

Demonstrates how to compose an HTML email with an embedded image where the image data is downloaded from a URL.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  // First download the image we'll be adding to the HTML "img" tag.
  final bdJpg = CkBinData();
  final http = CkHttp();
  try {
    http.quickGetBd('https://www.chilkatsoft.com/images/starfish.jpg', bdJpg);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final mailman = CkMailMan();

  // Use your SMTP server..
  mailman.smtpHost = 'smtp.yourserver.com';
  mailman.smtpPort = 587;
  mailman.startTLS = true;

  // Set the SMTP login/password
  mailman.smtpUsername = 'my_login';
  mailman.smtpPassword = 'my_password';

  // Create an HTML email.
  final email = CkEmail();
  email.subject = 'HTML Email with Image';
  email.from = 'Dave <somebody@mydomain.com>';
  email.addTo('Chilkat', 'info@chilkatsoft.com');

  final html = '<html><body><p>This is an HTML email with an embedded image.</p><p><img src="starfish.jpg" /></p></body></html>';
  email.setHtmlBody(html);

  // Note: The "starfish.jpg" here must match the name in the "img" tag's "src" attribute in the HTML above.
  try {
    email.addRelatedBd2(bdJpg, 'starfish.jpg');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  email.saveEml('qa_output/out.eml');

  // success = mailman.SendEmail(email);
  // if (success == ckfalse) {
  //     println mailman.LastErrorText;
  //     return;
  // }
  // 
  // ignore = mailman.CloseSmtpConnection();

  print('Success.');
}