| Visual Basic (Usage) | Copy Code |
|---|---|
Dim instance As Attachments Dim fileName As String Dim value As Integer value = instance.Add(fileName) | |
Parameters
- fileName
- The filename for the file to add as an attachment.
| Exception | Description |
|---|---|
| System.IO.IOException | The filename, directory name, or volume label syntax is incorrect. |
The following example demonstrates creating a basic MIME message with a single attachment.
| Visual Basic | Copy Code |
|---|---|
' Be sure to import the namespace by putting "Imports Dart.PowerTCP.Mail" ' at the top of your class. ' Create a MessageStream object Dim msg As New MessageStream() ' Add a normal recipient msg.To.Add(New MailAddress("you@test.com")) ' Add a CC recipient msg.CC.Add(New MailAddress("you2@test.com")) ' Add a BCC recipient msg.BCC.Add(New MailAddress("you3@test.com")) ' Specify the sender msg.From = New MailAddress("me@test.com") ' Specify the subject msg.Subject = "Hello" ' Add some text to the message. msg.Text = "Hi everyone. How are ya doing?" ' Add an attachment msg.Attachments.Add("C:\files\graph.jpg") ' Specify the server Smtp1.Server = "mail.test.com" ' Send the message Smtp1.Send(msg) | |
| C# | Copy Code |
|---|---|
// Be sure to import the namespace by putting "using Dart.PowerTCP.Mail;" // at the top of your class. // Create a MessageStream object MessageStream msg = new MessageStream(); // Add a normal recipient msg.To.Add(new MailAddress("you@test.com")); // Add a CC recipient msg.CC.Add(new MailAddress("you2@test.com")); // Add a BCC recipient msg.BCC.Add(new MailAddress("you3@test.com")); // Specify the sender msg.From = new MailAddress("me@test.com"); // Specify the subject msg.Subject = "Hello"; // Add some text to the message. msg.Text = "Hi everyone. How are ya doing?"; // Add an attachment msg.Attachments.Add("C:\\files\\graph.jpg"); // Specify the server smtp1.Server = "mail.test.com"; // Send the message smtp1.Send(msg); | |
Use this method to add a file to the collection as an attachment. Simply pass in a file name and a MimeAttachmentStream will be created containing data from this file. It will be Base64 encoded by default. Since the MessageStream.Attachments collection actually reflects the MessageStream.Parts.Attachments collection, a new MimeAttachmentStream will be added to the MessageStream.Parts.Attachments collection and the Message.Attachments collection will reflect this.
Target Platforms: Microsoft .NET Framework 2.0