mailer icon indicating copy to clipboard operation
mailer copied to clipboard

Building a Message with a Builder pattern

Open pjkroll opened this issue 6 years ago • 0 comments

I think it could be better to create a message with a builder pattern and make the message immutable:

Message msg = Message.Builder()
    ..from = new Address(username, 'Your name')
    ..recipients.add('[email protected]')
    ..subject = 'Test Dart Mailer library :: 😀 :: ${new DateTime.now()}'
    ..text = 'This is the plain text.\nThis is line 2 of the text part.'
    ..build()

class Message {
    Message._();
    // .... 
}

Inside build() you can make validation and create IRMessage. Message.Builder can also provide a validate() method. You are just passing validated Message to the .send() function. Validation should be done before calling send().

pjkroll avatar Feb 04 '19 19:02 pjkroll