Closed mminhlequang closed 2 years ago
I noticed that you add the text/plain
part twice. If you want to update that part, you can use code like this to update it:
final partBuilder = builder.getTextPlainPart();
if (partBuilder != null) {
partBuilder.text = text;
} else {
builder.addTextPlain(text);
}
Does this solve you problem?
So, Do you know how we can add multi images and text?
I noticed that you add the
text/plain
part twice. If you want to update that part, you can use code like this to update it:final partBuilder = builder.getTextPlainPart(); if (partBuilder != null) { partBuilder.text = text; } else { builder.addTextPlain(text); }
Does this solve you problem?
Thanks but it can't solve my problem
Ah, you are also setting a multipart/alternative
as the root mime part. I realize that the example I give was wrong, you probably want something like this:
final builder = MessageBuilder()
..from = [MailAddress('Personal Name', 'sender@domain.com')]
..to = [
MailAddress('Recipient Personal Name', 'recipient@domain.com'),
MailAddress('Other Recipient', 'other@domain.com')
];
builder.addMultipartAlternative()
..addTextPlain('Hello world!')
..addTextHtml('<p>Hello world!</p>');
builder.addBinary(Uint8List.fromList([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
MediaSubtype.imageJpeg.mediaType,
filename: 'helloworld.jpg',
);
final message = builder.buildMimeMessage();
The above code will create a multipart/mixed
message with the multipart/alternative
inside.
I will update the example code and I consider simplifying this use case for the next release.
Wow, Thanks I will try You need write it in example 👯
published correction now in 2.1.0
Please close when it works for you
Hi I don't work, you can try it at your side?
final builder = MessageBuilder() ..from = [MailAddress('Personal Name', 'sender@domain.com')] ..to = [ MailAddress('Recipient Personal Name', 'minh@xxx.com'), // MailAddress('Other Recipient', 'other@domain.com') ] ..addMultipartAlternative( plainText: 'Hello world plain text!', htmlText: '
Hello world html text!
', ); final file = File(xfile.path); await builder.addFile(file, MediaSubtype.imageJpeg.mediaType); final sendResponse = await client.sendMessage(builder.buildMimeMessage());
With new version, i updated same your example, and now it can sent html + image file, not have text: "Hello world plain text". it's normally?
Hi, yes that's expected. multipart/alternative
means that you have two version of the same thing and each viewer displays the content part that it can display best. E.g. a command line mailer would show the plain text part while most other mail apps would choose to display the html part.
Yes okay, thank you!
final builder = MessageBuilder.prepareMultipartAlternativeMessage() ..from = [MailAddress('My name', 'minh1@xxx.com')] ..to = [MailAddress('Your name', 'minh2@xxx.com')] ..subject = 'My first message' ..addTextPlain('hello world.') ..addTextHtml('
hello world
'); final file = File(xfile.path); await builder.addFile(file, MediaSubtype.imageJpeg.mediaType); await builder.addTextPlain('hello world2'); final mimeMessage = builder.buildMimeMessage(); final sendResponse = await client.sendMessage(mimeMessage);