AttachmentCollectionAdd Method (Byte, String, String, String, HeaderCollection, NewAttachmentOptions, MailTransferEncoding) |
Adds the attachment from a byte array.
Namespace: MailBee.MimeAssembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax public void Add(
byte[] data,
string targetFilename,
string contentID,
string contentType,
HeaderCollection customHeaders,
NewAttachmentOptions options,
MailTransferEncoding mailEnc
)
Public Sub Add (
data As Byte(),
targetFilename As String,
contentID As String,
contentType As String,
customHeaders As HeaderCollection,
options As NewAttachmentOptions,
mailEnc As MailTransferEncoding
)
Parameters
- data
- Type: SystemByte
The binary content of the attachment represented as a byte array. - targetFilename
- Type: SystemString
The filename under which to add the attachment into the collection. If an empty string, the attachment will have no name. - 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.
Exceptions Remarks Note |
---|
If you're attaching another e-mail message, be sure to use as None as mailEnc value. Some mail services
cannot decode attached emails if they are Base64-encoded. |
Examples This sample reads a file into memory buffer and adds it as attachment to the message.
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;
byte[] fileData = null;
using (FileStream fs = new FileStream(@"C:\Temp\1.gif", FileMode.Open))
{
fileData = new byte[fs.Length];
BinaryReader br = new BinaryReader(fs);
br.Read(fileData, 0, fileData.Length);
}
MailMessage msg = new MailMessage();
msg.Attachments.Add(fileData, "my.gif", "<12s4a8a8778c$5664i1b1$ir671781@tlffmdqjobxj>", "image/gif", null, NewAttachmentOptions.None, MailTransferEncoding.Base64);
Imports System.IO
Imports MailBee
Imports MailBee.Mime
Dim fileData As Byte() = Nothing
Dim fs As FileStream
Try
fs = New FileStream("C:\Temp\1.gif", System.IO.FileMode.Open)
ReDim fileData(fs.Length)
Dim br As New BinaryReader(fs)
br.Read(fileData, 0, fileData.Length)
Finally
If Not fs Is Nothing Then fs.Close()
End Try
Dim msg As New MailMessage
msg.Attachments.Add(fileData, "my.gif", "<12s4a8a8778c$5664i1b1$ir671781@tlffmdqjobxj>", "image/gif", Nothing, NewAttachmentOptions.None, MailTransferEncoding.Base64)
See Also