1

I can't seem to find any method that returns me just the encoded part of this e.ToString() output.

('e' is a MimeEntity with 1 singular email attachment)

This is what the output looks like:

X-MimeKit-Warning: Do NOT use ToString() to serialize entities! Use one of the WriteTo() methods instead!
Content-Type: image/png; name="px.png"
Content-Description: px.png
Content-Disposition: attachment; filename="px.png"; size=119;
        creation-date="Tue, 06 Apr 2021 09:24:23 GMT";
        modification-date="Tue, 06 Apr 2021 09:24:56 GMT"
Content-Transfer-Encoding: base64

iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAAXNSR0IArs4c6QAAAARnQU1BAACx
jwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAMSURBVBhXY/j//z8ABf4C/qc1gYQAAAAASUVO
RK5CYII=

The only thing I'm looking for would be this part:

iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAAXNSR0IArs4c6QAAAARnQU1BAACx
jwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAMSURBVBhXY/j//z8ABf4C/qc1gYQAAAAASUVO
RK5CYII=
Mxpsth
  • 67
  • 8
  • Did *Do NOT use ToString() to serialize entities! Use one of the WriteTo() methods instead!* prove to be helpful? – rene Apr 07 '21 at 09:56
  • @rene the WriteTo() method outputs everything that the ToString() method outputs, except for that "warning" sort of line. – Mxpsth Apr 07 '21 at 10:03
  • Did you try the overload that accepts a boolean, and set that boolean to true? http://www.mimekit.net/docs/html/M_MimeKit_MimeEntity_WriteTo_4.htm – rene Apr 07 '21 at 10:04
  • Oh... Looks like I didn't try that, when I read the documentation I didn't really understand all that "CancellationToken" thing so I decided not to touch that. Thank you rene. – Mxpsth Apr 07 '21 at 10:09

1 Answers1

1

You can use the WriteTo overload that accepts an boolean to indicate if you only want the content of the MimeEnity.

Like so


// 'e' is a MimeEntity

var ms = new MemoryStream();
e.WriteTo(ms, true); // no need to provide an cancellationtoken.

// ms will have only the content here

The third parameter cancellationtoken is null by default so you won't need to provide an instance of an token. That becomes only relevant if you want to gracefully end the WriteTo operation before it finished.

rene
  • 41,474
  • 78
  • 114
  • 152