AttachmentCollectionAdd Method (Stream, String, String, String, HeaderCollection, NewAttachmentOptions, MailTransferEncoding) |
Adds the attachment from a stream.
Namespace: MailBee.MimeAssembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax public bool Add(
Stream stream,
string targetFilename,
string contentID,
string contentType,
HeaderCollection customHeaders,
NewAttachmentOptions options,
MailTransferEncoding mailEnc
)
Public Function Add (
stream As Stream,
targetFilename As String,
contentID As String,
contentType As String,
customHeaders As HeaderCollection,
options As NewAttachmentOptions,
mailEnc As MailTransferEncoding
) As Boolean
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:
Booleantrue if the attachment was successfully added to the collection; otherwise,
false.
Exceptions 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 |
---|
In real-world apps, it's easier to use Add(String) overload to add an attachment from a file. |
using System.IO;
using MailBee;
using MailBee.Mime;
using (FileStream fs = new FileStream(@"C:\Docs\1.gif", FileMode.Open))
{
MailMessage msg = new MailMessage();
msg.BodyPlainText = "Hello, World!";
msg.Attachments.Add(fs, "pic1.gif", "<12s4a8a8778c$5664i1b1$ir671781@tlffmdqjobxj>", "image/gif", null, NewAttachmentOptions.None, MailTransferEncoding.Base64);
msg.SaveMessage(@"C:\Temp\SavedMessage.eml");
}
Imports System.IO
Imports MailBee
Imports MailBee.Mime
Dim fs As FileStream
fs = Nothing
Try
fs = New FileStream("C:\Docs\1.gif", FileMode.Open)
Dim msg As New MailMessage
msg.BodyPlainText = "Hello, World!"
msg.Attachments.Add(fs, "pic1.gif", "<12s4a8a8778c$5664i1b1$ir671781@tlffmdqjobxj>", "image/gif", Nothing, NewAttachmentOptions.None, MailTransferEncoding.None)
msg.SaveMessage("C:\Temp\SavedMessage.eml")
Finally
If Not fs Is Nothing Then fs.Close()
End Try
See Also