MailBee.NET Objects 4.0

AttachmentCollection.Add Method (String)

Adds the attachment from a file.

public bool Add(
   string filename
);

Parameters

filename
The absolute or relative path to the file which should be attached.

Return Value

true if the attachment was successfully added to the collection; otherwise, false.

Exceptions

Exception Type Condition
MailBeeInvalidArgumentException filename is a null reference (Nothing in Visual Basic) or an empty string.
MailBeeIOException An error occurred and ThrowExceptions is true.

Example

This sample loads the message from .EML file and adds an attachment to this message.

[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");

// Add the attachment to the message.
msg.Attachments.Add(@"C:\Temp\my_photo.jpg");
[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")

' Add the attachment to the message.
msg.Attachments.Add("C:\Temp\my_photo.jpg")

See Also

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