Adds a new MailAttachment object.
The MailAttachments index at which the value has been added.
To add a new item to a MailAttachments object, create a new MailAttachment object, set the MailAttachment object properties and pass this object to the Add method. You can also pass a file name string to the Add method to create a new MailAttachment object, load it from the path specified, and add it to the MailAttachments in one step.
| Exception Type | Condition |
|---|---|
| ArgumentNullException | value is a null reference (Nothing in Visual Basic). |
| ArgumentException |
value is not of type MailAttachment -or- value is not of type string. |
| FileNotFoundException | value represents a file that cannot be found. |
| SecurityException | The caller does not have the required permission. |
| DirectoryNotFoundException | value is an invalid path, such as being on an unmapped drive. |
| UnauthorizedAccessException | The access requested is not permitted by the operating system for the path specified by value. |
| PathTooLongException | The path specified by value exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters. |
| IOException | An I/O error occurs. |
| OutOfMemoryException | value content length exceeds the int.MaxValue value. |
This sample shows two different ways to add attachments to a Mail object.
Mail oMail = new Mail();
MailAttachment oAttachment = new MailAttachment();
oAttachment.Load(@"c:\documentation\product_specs.pdf");
oMail.Attachments.Add(oAttachment);
oMail.Attachments.Add(@"c:\documentation\product_help.pdf");
MailAttachments Class | MailMill Namespace | MailAttachment | Mail | Mail.MailAttachments