AttachmentCollectionAdd Method (Stream, String, String, String, HeaderCollection, NewAttachmentOptions, MailTransferEncoding)
Adds the attachment from a stream.

Namespace: MailBee.Mime
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 11.2.0 build 590 for .NET 4.5
Syntax
public bool Add(
	Stream stream,
	string targetFilename,
	string contentID,
	string contentType,
	HeaderCollection customHeaders,
	NewAttachmentOptions options,
	MailTransferEncoding mailEnc
)

Parameters

stream
Type: System.IOStream
The data stream from which to read the binary content of the attachment.
targetFilename
Type: SystemString
The filename under which to add the attachment into the collection.
contentID
Type: SystemString
The content identifier (CID) of the attachment (for inline attachments), or empty string if the attachment is not inline.
contentType
Type: SystemString
The content type of the attachment, or a null reference (Nothing in Visual Basic) to let MailBee detect the content type automatically.
customHeaders
Type: MailBee.MimeHeaderCollection
The collection of the headers which should be included into the header section in additon to the standard attachment headers. If a null reference (Nothing in Visual Basic), no custom headers will be added.
options
Type: MailBee.MimeNewAttachmentOptions
The options which affect how the attachment is added.
mailEnc
Type: MailBee.MimeMailTransferEncoding
The mail encoding to use when placing the attachment data into the message.

Return Value

Type: Boolean
true if the attachment was successfully added to the collection; otherwise, false.
Exceptions
ExceptionCondition
MailBeeInvalidArgumentExceptionstream or targetFilename is a null reference (Nothing in Visual Basic).
MailBeeStreamExceptionAn error occurred and ThrowExceptions is true.
Remarks
The targetFilename parameter allows the developer to override the filename under which the attachment will be added to the collection. This is useful if the attachment is being added from a temporary file such as ETQB4914.TMP under meaningful name such as report.doc.
Examples
This sample opens a file stream, reads the file into the stream, adds the attachment from the stream, and saves the message to disk.
Note Note
In real-world apps, it's easier to use Add(String) overload to add an attachment from a file.
// To use the code below, import these namespaces at the top of your code.
using System.IO;
using MailBee;
using MailBee.Mime;

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

// Open the file as stream for reading.
using (FileStream fs = new FileStream(@"C:\Docs\1.gif", FileMode.Open))
{
    // Create new MailMessage object.
    MailMessage msg = new MailMessage();

    // Set plain text body of the message.
    msg.BodyPlainText = "Hello, World!";

    // Add the attachment to the message.
    msg.Attachments.Add(fs, "pic1.gif", "<12s4a8a8778c$5664i1b1$ir671781@tlffmdqjobxj>", "image/gif", null, NewAttachmentOptions.None, MailTransferEncoding.Base64);

    // Save message to disk.
    msg.SaveMessage(@"C:\Temp\SavedMessage.eml");
}
See Also