pip_clients_email 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 71

Pip.Services Logo
Email Microservice Client SDK for Dart #

This is a Dart client SDK for pip-services-email microservice. It provides an easy to use abstraction over communication protocols:

  • HTTP client
  • Direct client for monolythic deployments
  • Null client to be used in testing

In addition to the microservice functionality the client SDK supports message templates that can be configured by client user.

Quick Links:

Install #

Add pip-services3-commons-dart and pip_clients_email packages

import 'package:pip_services3_commons/pip_services3_commons.dart';
import 'package:pip_clients_email/pip_clients_email.dart';

Use #

Define client configuration parameters that match configuration of the microservice external API

// Client configuration
var config = ConfigParams.fromTuples(
	"connection.protocol", "http",
	"connection.host", "localhost",
	"connection.port", 8080
);

Instantiate the client and open connection to the microservice

// Create the client instance
var client = EmailHttpClientV1(config);

// Connect to the microservice
await client.open(null);
    
    // Work with the microservice
    ...
});

Now the client is ready to perform operations

// Send email message to address
        var message = EmailMessageV1(to: 'somebody@somewhere.com',
            subject: '{{subject}}',
            text: '{{text}}',
            html: '<p>{{text}}</p>');

        var parameters = ConfigParams.fromTuples([
            'subject', 'Test Email To Address',
            'text', 'This is just a test'
        ]);

await client.sendMessage(
    null,
    message,
    parameters
);
// Send email message to users
var recipient1 = EmailRecipientV1(id: '1', email: 'user1@somewhere.com');
var recipient2 = EmailRecipientV1(id: '2', email: 'user2@somewhere.com');
var message = EmailMessageV1(subject: 'Test', 
                             text: 'This is a test message. Please, ignore it');
await client.sendMessageToRecipients(
    null,
    [
        recipient1,
        recipient2
    ],
    message,
    null
);

To use templates for sent messages you need to put template files under configured template folder. Inside template you shall use <%= property %> syntax to insert properties from provided content defined in client configuration and request parameters.

Example of message.txt template

Hello <%= user_name %>!

This is a test message from <%= client_name %> sent on <%= today %>.
Please, ignore it.

Example of message.html template

Hello <%= user_name %>!
<p>
This is a test message from <%= client_name %> sent on <%= today %>. 
<br/>
Please, ignore it.
</p>

Now you can send a message using the templates stored in files. subjectTemplate, textTemplate and htmlTemplate parameters shall contain the template file paths. Client will automatically load their content and parse.

// Send email message to address using template
var message = EmailMessageV1(to: 'somebody@somewhere.com', 
                             subject: File('./templates/message_subject.txt').readAsStringSync(), 
                             text: File('./templates/message.txt').readAsStringSync(),
                             html: File('./templates/message.html').readAsStringSync());
var parameters = ConfigParams.fromTuples([
        'user_name', 'Somebody',
        'today': DateTime.now().toIso8601String()
    ]);
await client.sendMessage(
    null,
    message,
    parameters
);

This microservice was created and currently maintained by

  • Sergey Seroukhov
  • Denis Kuznetsov
  • Nuzhnykh Egor.

1.0.0 #

  • Initial version

1.0.1 #

  • Added direct client test

example/README.md

Examples for Email Delivery Microservice #

This is a user account management microservice from Pip.Services library.

  • Registers users and creates their accounts
  • Keeps key user descriptions and settings (about, location, language, theme, ...)

Define client configuration parameters that match the configuration of the microservice's external API

// Client configuration
var httpConfig = ConfigParams.fromTuples(
	"connection.protocol", "http",
	"connection.host", "localhost",
	"connection.port", 8080
);

Instantiate the client and open connection to the microservice

// Create the client instance
var client = EmailHttpClientV1();

// Configure the client
client.configure(httpConfig);

// Connect to the microservice
try{
  await client.open(null)
}catch() {
  // Error handling...
}       
// Work with the microservice
// ...

Now the client is ready to perform operations

// Send email message to address
        var message = EmailMessageV1(to: 'somebody@somewhere.com',
            subject: '{{subject}}',
            text: '{{text}}',
            html: '<p>{{text}}</p>');

        var parameters = ConfigParams.fromTuples([
            'subject', 'Test Email To Address',
            'text', 'This is just a test'
        ]);

await client.sendMessage(
    null,
    message,
    parameters
);
// Send email message to users
var recipient1 = EmailRecipientV1(id: '1', email: 'user1@somewhere.com');
var recipient2 = EmailRecipientV1(id: '2', email: 'user2@somewhere.com');
var message = EmailMessageV1(subject: 'Test', 
                             text: 'This is a test message. Please, ignore it');
await client.sendMessageToRecipients(
    null,
    [
        recipient1,
        recipient2
    ],
    message,
    null
);

In the help for each class there is a general example of its use. Also one of the quality sources are the source code for the tests.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  pip_clients_email: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:pip_clients_email/pip_clients_email.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
42
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
71
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14

Analysis suggestions

Package not compatible with SDK flutter

Because it is not compatible with any of the supported runtimes: flutter-native, flutter-web

Package not compatible with runtime flutter-native on android

Because:

  • package:pip_clients_email/pip_clients_email.dart that imports:
  • package:pip_clients_email/src/version1/version1.dart that imports:
  • package:pip_clients_email/src/version1/EmailNullClientV1.dart that imports:
  • package:pip_clients_email/src/version1/IEmailClientV1.dart that imports:
  • package:pip_services_email/pip_services_email.dart that imports:
  • package:pip_services_email/src/services/version1/service.dart that imports:
  • package:pip_services_email/src/services/version1/EmailHttpServiceV1.dart that imports:
  • package:pip_services3_rpc/pip_services3_rpc.dart that imports:
  • package:pip_services3_rpc/src/build/build.dart that imports:
  • package:pip_services3_rpc/src/build/DefaultRpcFactory.dart that imports:
  • package:pip_services3_rpc/src/services/StatusRestService.dart that imports:
  • package:pip_services3_rpc/src/services/RestService.dart that imports:
  • package:pip_services3_rpc/src/services/HttpResponseSender.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on ios

Because:

  • package:pip_clients_email/pip_clients_email.dart that imports:
  • package:pip_clients_email/src/version1/version1.dart that imports:
  • package:pip_clients_email/src/version1/EmailNullClientV1.dart that imports:
  • package:pip_clients_email/src/version1/IEmailClientV1.dart that imports:
  • package:pip_services_email/pip_services_email.dart that imports:
  • package:pip_services_email/src/services/version1/service.dart that imports:
  • package:pip_services_email/src/services/version1/EmailHttpServiceV1.dart that imports:
  • package:pip_services3_rpc/pip_services3_rpc.dart that imports:
  • package:pip_services3_rpc/src/build/build.dart that imports:
  • package:pip_services3_rpc/src/build/DefaultRpcFactory.dart that imports:
  • package:pip_services3_rpc/src/services/StatusRestService.dart that imports:
  • package:pip_services3_rpc/src/services/RestService.dart that imports:
  • package:pip_services3_rpc/src/services/HttpResponseSender.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on linux

Because:

  • package:pip_clients_email/pip_clients_email.dart that imports:
  • package:pip_clients_email/src/version1/version1.dart that imports:
  • package:pip_clients_email/src/version1/EmailNullClientV1.dart that imports:
  • package:pip_clients_email/src/version1/IEmailClientV1.dart that imports:
  • package:pip_services_email/pip_services_email.dart that imports:
  • package:pip_services_email/src/services/version1/service.dart that imports:
  • package:pip_services_email/src/services/version1/EmailHttpServiceV1.dart that imports:
  • package:pip_services3_rpc/pip_services3_rpc.dart that imports:
  • package:pip_services3_rpc/src/build/build.dart that imports:
  • package:pip_services3_rpc/src/build/DefaultRpcFactory.dart that imports:
  • package:pip_services3_rpc/src/services/StatusRestService.dart that imports:
  • package:pip_services3_rpc/src/services/RestService.dart that imports:
  • package:pip_services3_rpc/src/services/HttpResponseSender.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on macos

Because:

  • package:pip_clients_email/pip_clients_email.dart that imports:
  • package:pip_clients_email/src/version1/version1.dart that imports:
  • package:pip_clients_email/src/version1/EmailNullClientV1.dart that imports:
  • package:pip_clients_email/src/version1/IEmailClientV1.dart that imports:
  • package:pip_services_email/pip_services_email.dart that imports:
  • package:pip_services_email/src/services/version1/service.dart that imports:
  • package:pip_services_email/src/services/version1/EmailHttpServiceV1.dart that imports:
  • package:pip_services3_rpc/pip_services3_rpc.dart that imports:
  • package:pip_services3_rpc/src/build/build.dart that imports:
  • package:pip_services3_rpc/src/build/DefaultRpcFactory.dart that imports:
  • package:pip_services3_rpc/src/services/StatusRestService.dart that imports:
  • package:pip_services3_rpc/src/services/RestService.dart that imports:
  • package:pip_services3_rpc/src/services/HttpResponseSender.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on windows

Because:

  • package:pip_clients_email/pip_clients_email.dart that imports:
  • package:pip_clients_email/src/version1/version1.dart that imports:
  • package:pip_clients_email/src/version1/EmailNullClientV1.dart that imports:
  • package:pip_clients_email/src/version1/IEmailClientV1.dart that imports:
  • package:pip_services_email/pip_services_email.dart that imports:
  • package:pip_services_email/src/services/version1/service.dart that imports:
  • package:pip_services_email/src/services/version1/EmailHttpServiceV1.dart that imports:
  • package:pip_services3_rpc/pip_services3_rpc.dart that imports:
  • package:pip_services3_rpc/src/build/build.dart that imports:
  • package:pip_services3_rpc/src/build/DefaultRpcFactory.dart that imports:
  • package:pip_services3_rpc/src/services/StatusRestService.dart that imports:
  • package:pip_services3_rpc/src/services/RestService.dart that imports:
  • package:pip_services3_rpc/src/services/HttpResponseSender.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-web on web

Because:

  • package:pip_clients_email/pip_clients_email.dart that imports:
  • package:pip_clients_email/src/version1/version1.dart that imports:
  • package:pip_clients_email/src/version1/EmailNullClientV1.dart that imports:
  • package:pip_clients_email/src/version1/IEmailClientV1.dart that imports:
  • package:pip_services_email/pip_services_email.dart that imports:
  • package:pip_services_email/src/services/version1/service.dart that imports:
  • package:pip_services_email/src/services/version1/EmailHttpServiceV1.dart that imports:
  • package:pip_services3_rpc/pip_services3_rpc.dart that imports:
  • package:pip_services3_rpc/src/build/build.dart that imports:
  • package:pip_services3_rpc/src/build/DefaultRpcFactory.dart that imports:
  • package:pip_services3_rpc/src/services/StatusRestService.dart that imports:
  • package:pip_services3_rpc/src/services/RestService.dart that imports:
  • package:pip_services3_rpc/src/services/HttpResponseSender.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Package not compatible with runtime js

Because:

  • package:pip_clients_email/pip_clients_email.dart that imports:
  • package:pip_clients_email/src/version1/version1.dart that imports:
  • package:pip_clients_email/src/version1/EmailNullClientV1.dart that imports:
  • package:pip_clients_email/src/version1/IEmailClientV1.dart that imports:
  • package:pip_services_email/pip_services_email.dart that imports:
  • package:pip_services_email/src/services/version1/service.dart that imports:
  • package:pip_services_email/src/services/version1/EmailHttpServiceV1.dart that imports:
  • package:pip_services3_rpc/pip_services3_rpc.dart that imports:
  • package:pip_services3_rpc/src/build/build.dart that imports:
  • package:pip_services3_rpc/src/build/DefaultRpcFactory.dart that imports:
  • package:pip_services3_rpc/src/services/StatusRestService.dart that imports:
  • package:pip_services3_rpc/src/services/RestService.dart that imports:
  • package:pip_services3_rpc/src/services/HttpResponseSender.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Package not compatible with runtime native-aot

Because:

  • package:pip_clients_email/pip_clients_email.dart that imports:
  • package:pip_clients_email/src/version1/version1.dart that imports:
  • package:pip_clients_email/src/version1/EmailNullClientV1.dart that imports:
  • package:pip_clients_email/src/version1/IEmailClientV1.dart that imports:
  • package:pip_services_email/pip_services_email.dart that imports:
  • package:pip_services_email/src/services/version1/service.dart that imports:
  • package:pip_services_email/src/services/version1/EmailHttpServiceV1.dart that imports:
  • package:pip_services3_rpc/pip_services3_rpc.dart that imports:
  • package:pip_services3_rpc/src/build/build.dart that imports:
  • package:pip_services3_rpc/src/build/DefaultRpcFactory.dart that imports:
  • package:pip_services3_rpc/src/services/StatusRestService.dart that imports:
  • package:pip_services3_rpc/src/services/RestService.dart that imports:
  • package:pip_services3_rpc/src/services/HttpResponseSender.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
angel_framework ^2.1.1 2.1.1
http ^0.12.0 0.12.1
pip_services3_commons >=1.0.7 <2.0.0 1.0.11
pip_services3_components >=1.0.2 <2.0.0 1.0.6
pip_services3_data >=1.0.0 <2.0.0 1.0.6
pip_services3_rpc >=1.0.2 <2.0.0 1.0.7
pip_services_email >=1.0.1 <2.0.0 1.0.1
Transitive dependencies
angel_container 1.1.0
angel_http_exception 1.1.0
angel_model 1.0.3
angel_route 3.1.0+1
async 2.4.2
bson 0.3.2
charcode 1.1.3
code_buffer 1.0.1
collection 1.14.13 1.15.0-nullsafety
combinator 1.1.0
convert 2.1.1
crypto 2.1.5
dart2_constant 1.0.2+dart2
file 5.2.1
fixnum 0.10.11
googleapis_auth 0.2.12
grpc 2.2.0
http2 1.0.0
http_parser 3.1.4
http_server 0.9.8+3
intl 0.16.1
logging 0.11.4
mailer 3.0.4
matcher 0.12.8
merge_map 1.0.2
meta 1.2.2 1.3.0-nullsafety
mime 0.9.6+3
mock_request 1.0.7
mongo_dart 0.4.0
mongo_dart_query 0.4.1
more 1.18.2 2.5.0
mustache4dart2 0.1.0
path 1.7.0
pedantic 1.9.2
pip_services3_container 1.0.3
pip_services3_grpc 1.0.0
pip_services3_mongodb 1.0.4
pool 1.4.0
protobuf 1.0.1
quiver 2.1.3
quiver_hashcode 2.0.0
recase 2.0.1 3.0.0
source_span 1.7.0
sprintf 4.0.2
stack_trace 1.9.5
string_scanner 1.0.5
term_glyph 1.1.0
tuple 1.0.3
typed_data 1.2.0 1.3.0-nullsafety
uuid 2.2.0
yaml 2.2.1
Dev dependencies
test >=1.14.2 <2.0.0