MessageBuilder class

Simplifies creating mime messages for sending or storing.

Inheritance

Constructors

MessageBuilder({String? text, TransferEncoding transferEncoding = TransferEncoding.automatic, CharacterSet? characterSet, ContentTypeHeader? contentType, HeaderEncoding subjectEncoding = HeaderEncoding.Q})
Creates a new message builder and populates it with the optional data.
MessageBuilder.prepareForwardMessage(MimeMessage originalMessage, {MailAddress? from, String forwardHeaderTemplate = MailConventions.defaultForwardHeaderTemplate, String defaultForwardAbbreviation = MailConventions.defaultForwardAbbreviation, bool quoteMessage = true, HeaderEncoding subjectEncoding = HeaderEncoding.Q, bool forwardAttachments = true})
Prepares to forward the given originalMessage.
factory
MessageBuilder.prepareFromDraft(MimeMessage draft)
Prepares a message builder from the specified draft mime message.
factory
MessageBuilder.prepareMailtoBasedMessage(Uri mailto, MailAddress from)
Convenience method for creating a message based on a mailto URI from the sender specified in from.
factory
MessageBuilder.prepareMessageWithMediaType(MediaSubtype subtype, {TransferEncoding transferEncoding = TransferEncoding.eightBit})
Convenience method to init a message with the specified media subtype
factory
MessageBuilder.prepareMultipartAlternativeMessage({String? plainText, String? htmlText, TransferEncoding transferEncoding = TransferEncoding.eightBit})
Convenience method for initiating a multipart/alternative message
factory
MessageBuilder.prepareMultipartMixedMessage({TransferEncoding transferEncoding = TransferEncoding.eightBit})
Convenience method for initiating a multipart/mixed message
factory
MessageBuilder.prepareReplyToMessage(MimeMessage originalMessage, MailAddress from, {bool replyAll = true, bool quoteOriginalText = false, bool preferPlainText = false, String replyHeaderTemplate = MailConventions.defaultReplyHeaderTemplate, String defaultReplyAbbreviation = MailConventions.defaultReplyAbbreviation, bool replyToSimplifyReferences = false, List<MailAddress>? aliases, bool handlePlusAliases = false, HeaderEncoding subjectEncoding = HeaderEncoding.Q})
Prepares to create a reply to the given originalMessage to be send by the user specified in from.
factory

Properties

attachments → List<AttachmentInfo>
The attachments in this builder
no setterinherited
bcc ↔ List<MailAddress>?
bcc recipients
getter/setter pair
cc ↔ List<MailAddress>?
cc recipients
getter/setter pair
characterSet ↔ CharacterSet?
The char set like ASCII or UTF-8 used in the text
getter/setter pairinherited
chatGroupId ↔ String?
Specify in case this is a chat group discussion
getter/setter pair
contentDisposition ↔ ContentDispositionHeader?
The way that this part should be handled, e.g. inline or as attachment.
getter/setter pairinherited
contentType ↔ ContentTypeHeader?
The media type represented by this part
getter/setter pairinherited
date ↔ DateTime?
Message date
getter/setter pair
from ↔ List<MailAddress>?
List of senders, typically this is only one sender
getter/setter pair
hasAttachments → bool
Checks if there is at least 1 attachment
no setterinherited
hashCode → int
The hash code for this object.
no setterinherited
isChat ↔ bool
Set to true to set chat headers
getter/setter pair
messageId ↔ String?
ID of the message
getter/setter pair
originalMessage ↔ MimeMessage?
Reference to original message
getter/setter pair
replyToSimplifyReferences ↔ bool
Set to true in case only the last replied to message should be referenced. Useful for long threads.
getter/setter pair
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
sender ↔ MailAddress?
One sender in case there are different from senders
getter/setter pair
subject ↔ String?
Message subject
getter/setter pair
subjectEncoding ↔ HeaderEncoding
Header encoding type
getter/setter pair
text ↔ String?
the text in this part builder
getter/setter pairinherited
to ↔ List<MailAddress>?
to recipients
getter/setter pair
transferEncoding ↔ TransferEncoding
The scheme used for encoding 8bit characters in the text
getter/setter pairinherited

Methods

addBinary(Uint8List data, MediaType mediaType, {TransferEncoding transferEncoding = TransferEncoding.base64, ContentDispositionHeader? disposition, String? filename}) → PartBuilder
Adds a binary data part with the given mediaType.
inherited
addFile(File file, MediaType mediaType, {ContentDispositionHeader? disposition}) → Future<PartBuilder>
Adds the file part asynchronously.
inherited
addHeader(String name, String value, {HeaderEncoding encoding = HeaderEncoding.none}) → void
Adds a header with the specified name and value.
inherited
addMailAddressHeader(String name, List<MailAddress> addresses) → void
Adds another header with the specified name
inherited
addMessagePart(MimeMessage mimeMessage, {ContentDisposition disposition = ContentDisposition.attachment}) → PartBuilder
Adds the message mimeMessage as a message/rfc822 content.
inherited
addMultipartAlternative({String? plainText, String? htmlText}) → PartBuilder
Adds a part with the multipart/alternative subtype.
inherited
addPart({ContentDispositionHeader? disposition, MimePart? mimePart, MediaSubtype? mediaSubtype, bool insert = false}) → PartBuilder
Adds a new part
inherited
addRecipient(MailAddress recipient, {RecipientGroup group = RecipientGroup.to}) → void
Adds a recipient.
addText(String text, {MediaType? mediaType, TransferEncoding transferEncoding = TransferEncoding.automatic, CharacterSet characterSet = CharacterSet.utf8, ContentDispositionHeader? disposition, bool insert = false}) → PartBuilder
Adds a text part to this message with the specified text.
inherited
addTextHtml(String text, {TransferEncoding transferEncoding = TransferEncoding.automatic, CharacterSet characterSet = CharacterSet.utf8, ContentDispositionHeader? disposition, bool insert = false}) → PartBuilder
Adds a HTML text part
inherited
addTextPlain(String text, {TransferEncoding transferEncoding = TransferEncoding.automatic, CharacterSet characterSet = CharacterSet.utf8, ContentDispositionHeader? disposition, bool insert = false}) → PartBuilder
Adds a plain text part
inherited
buildMimeMessage() → MimeMessage
Creates the mime message based on the previous input.
clearRecipients() → void
Removes all recipients from this message.
getPart(MediaSubtype mediaSubtype, {bool recursive = true}) → PartBuilder?
Retrieves the first builder with the specified mediaSubtype.
inherited
getTextHtmlPart() → PartBuilder?
Retrieves the first builder with a text/plain part.
inherited
getTextPlainPart() → PartBuilder?
Retrieves the first builder with a text/plain part.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeAttachment(AttachmentInfo info) → void
Removes the specified attachment info
inherited
removeHeader(String name) → void
Removes the header with the specified name.
inherited
removePart(PartBuilder childBuilder) → void
Removes the specified part childBuilder
inherited
removeReadReceiptRequest() → void
Removes the read receipt request.
removeRecipient(MailAddress recipient) → void
Removes the specified recipient from To/Cc/Bcc fields.
requestReadReceipt({MailAddress? recipient}) → void
Requests a read receipt
setContentType(MediaType mediaType, {CharacterSet? characterSet, String? multiPartBoundary, String? name, Map<String, String>? parameters}) → void
Creates the content-type based on the specified mediaType.
inherited
setHeader(String name, String? value, {HeaderEncoding encoding = HeaderEncoding.none}) → void
Sets a header with the specified name and value
inherited
setMailAddressHeader(String name, List<MailAddress> addresses) → void
Adds the header with the specified name
inherited
setRecommendedTextEncoding({bool supports8BitMessages = false}) → TransferEncoding
Sets the transfer encoding to the recommended one.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

buildReadReceipt(MimeMessage originalMessage, MailAddress finalRecipient, {String reportingUa = 'enough_mail', bool isAutomaticReport = false, String subject = 'read receipt', String textTemplate = MailConventions.defaultReadReceiptTemplate}) → MimeMessage
Builds a disposition notification report for the given originalMessage
buildSimpleTextMessage(MailAddress from, List<MailAddress> to, String text, {List<MailAddress>? cc, List<MailAddress>? bcc, String? subject, HeaderEncoding subjectEncoding = HeaderEncoding.Q, DateTime? date, MimeMessage? replyToMessage, bool replyToSimplifyReferences = false, String? messageId, CharacterSet characterSet = CharacterSet.utf8, TransferEncoding transferEncoding = TransferEncoding.quotedPrintable}) → MimeMessage
Creates a text message.
createForwardSubject(String originalSubject, {String defaultForwardAbbreviation = MailConventions.defaultForwardAbbreviation}) → String
Creates a subject based on the originalSubject taking mail conventions into account.
createMessageId(String? hostName, {bool isChat = false, String? chatGroupId}) → String
Generates a message ID
createRandomId({int length = 18}) → String
Creates a new randomized ID text.
createReplySubject(String originalSubject, {String defaultReplyAbbreviation = MailConventions.defaultReplyAbbreviation}) → String
Creates a subject based on the originalSubject taking mail conventions into account.
encodeHeaderValue(String value, [TransferEncoding transferEncoding = TransferEncoding.quotedPrintable]) → String
Encodes the specified header value.
encodeText(String text, TransferEncoding transferEncoding, [CharacterSet characterSet = CharacterSet.utf8]) → String
Encodes the specified text with given transferEncoding.
fillTemplate(String template, MimeMessage message, {Map<String, String>? parameters}) → String
Fills the given template with values extracted from the provided message.
fromContentTransferEncodingName(String name) → TransferEncoding
Detects the transfer encoding from the given name.
getCharacterSetName(CharacterSet? characterSet) → String
Retrieves the name of the specified characterSet.
getCodec(CharacterSet? characterSet) → Codec
Retrieves the codec for the specified characterSet.
getContentTransferEncodingName(TransferEncoding encoding) → String
Retrieves the name of the specified encoding.
quotePlainText(String header, String? text) → String
Quotes the given plain text header and text.