pip_clients_email 1.1.0 copy "pip_clients_email: ^1.1.0" to clipboard
pip_clients_email: ^1.1.0 copied to clipboard

Clients for Email Delivery microservice for Pip.Services in Dart. This microservice sends emails to specified recipients.

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.
0
likes
110
pub points
1%
popularity

Publisher

verified publisherentinco.com

Clients for Email Delivery microservice for Pip.Services in Dart. This microservice sends emails to specified recipients.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

http, pip_services3_commons, pip_services3_components, pip_services3_data, pip_services3_rpc, pip_services_email

More

Packages that depend on pip_clients_email