MailBee.NET Objects 4.0

AttachmentCollection.SaveAll Method (String, Boolean)

Saves real (and, optionally, inline) attachments.

public bool SaveAll(
   string folderName,
   bool ignoreInlineAttachments
);

Parameters

folderName
The absolute or relative path to the folder where to save the attachments.
ignoreInlineAttachments
If true, only real attachments (not inline) will be saved; otherwise, both inline and not inline attachments will be saved.

Return Value

true if all attachments were successfully saved; otherwise, false.

Remarks

If the specified folder does not exist, MailBee will try to create it first.

Attachments having duplicate filenames will be renamed and then saved. For instance, if there are three attachments with my_cat.jpg filename, they will be saved to disk under the following filenames:

For each attachment, SavedAs property can be examined to get the actual file path each file was saved under.

Note    Inline attachments are usually used in the process of rendering the HTML body of the message. Thus, they are usually saved to disk by methods like GetHtmlAndSaveRelatedFiles. The current method, on other hand, is useful when the developer wants to save only real attachments (files which were explicitly attached to the message by the sender) and skip any files which have already been rendered with the message body.

Exceptions

Exception TypeCondition
MailBeeInvalidArgumentExceptionfolderName is a null reference (Nothing in Visual Basic) or an empty string.
MailBeeIOExceptionAn error occurred and ThrowExceptions is true.

Example

This sample loads the message from .EML file and saves all attachments to the specified folder.

[C#]
// To use the code below, import MailBee namespaces at the top of your code.
using MailBee;
using MailBee.Mime;

// The actual code (put it into a method of your class)

' Load the message from file.
MailMessage msg = new MailMessage();
msg.LoadMessage(@"C:\Docs\TestMail.eml");

// Save all attachments to folder.
msg.Attachments.SaveAll(@"C:\Temp", false);
[Visual Basic]
' To use the code below, import MailBee namespaces at the top of your code.
Imports MailBee
Imports MailBee.Mime

' The actual code (put it into a method of your class)

' Load the message from file.
Dim msg As New MailMessage
msg.LoadMessage("C:\Docs\TestMail.eml")

' Save all attachments to folder.
msg.Attachments.SaveAll("C:\Temp", False)

See Also

AttachmentCollection Class | MailBee.Mime Namespace | AttachmentCollection.SaveAll Overload List | Attachment