mailer
mailer copied to clipboard
Building a Message with a Builder pattern
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().