PowerTCP Mail for .NET
Add(String) Method
See Also  Example Send comments on this topic.
Dart.PowerTCP.Mail Namespace > Attachments Class > Add Method : Add(String) Method




fileName
The filename for the file to add as an attachment.
Inserts the file specified by fileName into the collectio as an attachment.

Syntax

Visual Basic (Declaration) 
Public Overloads Function Add( _
   ByVal fileName As String _
) As Integer
Visual Basic (Usage)Copy Code
Dim instance As Attachments
Dim fileName As String
Dim value As Integer
 
value = instance.Add(fileName)
C# 
public int Add( 
   string fileName
)
Managed Extensions for C++ 
public: int Add( 
   string* fileName
) 
C++/CLI 
public:
int Add( 
   String^ fileName
) 

Parameters

fileName
The filename for the file to add as an attachment.

Exceptions

ExceptionDescription
System.IO.IOExceptionThe filename, directory name, or volume label syntax is incorrect.

Example

The following example demonstrates creating a basic MIME message with a single attachment.
Visual BasicCopy 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);

Remarks

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.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.