MailMessageClear Method |
Namespace: MailBee.Mime
To clear the entire message (i.e. to reset all its properties to default values), the developer should use Reset method.
To clear raw body of the message, you can use Msg.Clear(MessageElements.RawBody) call. This is useful if you already received an e-mail and parsed it. If you have no plans to further access the raw data of the e-mail (e.g. write the e-mail into .EML file), you do not need the raw body data (which might be very large), and can free it. However, if you then call and method or property which operates on the raw body (such as Size property), the message will be rebuilt and the raw body regenerated. Be sure to call all such properties and methods BEFORE clearing the raw body.
Another purpose of Msg.Clear(MessageElements.RawBody) is after sending a very large e-mail. For instance, you're sending multiple very large e-mails and want to have as much free memory as possible before every e-mail gets built to avoid out-of-memory issues. You can use Reset method and then call Collect(Int32) (GC.Collect) but this will also remove all the attachments and other parts of the message. In case if you want to send the same attachments in multiple e-mails, this would degrade performance. With Msg.Clear(MessageElements.RawBody) you can preserve the attachments already loaded and free only the generated raw message data.
using MailBee; using MailBee.Pop3Mail; using MailBee.Mime; class Sample { static void Main(string[] args) { // Download the first mail message from the specified POP3 account. MailMessage msg = Pop3.QuickDownloadMessage("pop.mail.com", "kathy", "password", 1); // Remove all attachments and recipients from the message and save this message to disk. msg.Clear(MessageElements.Attachments | MessageElements.Recipients); msg.SaveMessage(@"C:\Temp\msg.eml"); } }